GetSimple Support Forum

Full Version: Components specific to the page - How?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know I have seen somewhere how to do this but can't find the info - to have a different component on a different page without making a new page template.

To be clear, what I am trying to do is to put a mini thumbnail gallery in the sidebar with i18n galleries, but on the page 'Sheep' I want the gallery of sheep, on the page 'Goats' I want the goat gallery and on Home I don't want any gallery at all; so I will have different components for the different sidebar contents, and I want them to appear on the right pages
i think this is how you do it, ...if not, someone will chastise me!
Setup a component for each and inside your sidebar template, place the following:
Code:
<?php if (get_parent(0)=='Sheep') get_component('Sheep'); ?>
Code:
<?php if (get_parent(0)=='Goats') get_component('Goats'); ?>
Just use the slug in the component name when calling it.
Okay, so I make a page with the slug sheep
Then I make a component with the slug sidebar-sheep
Likewise I make a page with the slug goats
Then I make a component with the slug sidebar-goats

Then in my template I call the sidebar with something like
<?php get_component('sidebar-get_page_slug()'); ?>
But I have to do something with the brackets or quotes don't I?

I found Mvlcek's instructions here:
http://mvlcek.bplaced.net/how-to/sidebars/
but he has an if else thing (which is good) to use the default sidebar and he gets an i18n_component which I don't understand. also an extra .(full stop / period) .
PHP Code:
get_component('sidebar-'.get_page_slug()); 

You oly need a check function if you want to use a default if the component does not exist.
thanks Shawn,

I must get that php course out one day.
PHP Code:
get_component('sidebar-'.get_page_slug(false)); 

...so that it doesn't echo the slug.
yeah or you can use return_page_slug()

PHP Code:
function return_page_slug() {
  return 
get_page_slug(FALSE);


my bad was just copying psuedocode
:-)

...or my favorite: get_page_slug(0)
(shorter!)
I am still not getting this right. I have a site with banner type header images across the tops of the pages. The homepage has a slideshow of images and the slideshow is the default unless a specific static image is assigned to a page. I have put the slideshow and the static images in components which I am calling with the following:
PHP Code:
<div class="banner">
                <?
php  if (get_component('banner-'.get_page_slug(false)))
                                {
get_component('banner-'.get_page_slug(false));}
                        else {
get_component('slideshow');}    ?>
            </div> 
I get the slideshow alright on the homepage, but where I have a page specific image in a component I get both the static image and the slideshow below it displayed on the page.

Help appreciated.
You could use this:
http://get-simple.info/forums/showthread...9#pid24159

And then change this:

Code:
if (get_component('banner-'.get_page_slug(false)))

by:

Code:
if (component_exists('banner-'.get_page_slug(false)))
all working! Thanks Carlos
I didn't need to publish a component on one page of my site. So I wrote this code:

Code:
if( return_page_slug() == 'page1' ) {
get_component( FALSE );
} else {
get_component( 'my_component' );
}

It worked!