Posts: 1,127
Threads: 136
Joined: Feb 2012
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
Posts: 79
Threads: 2
Joined: Feb 2012
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'); ?>
Posts: 6,267
Threads: 182
Joined: Sep 2011
Just use the slug in the component name when calling it.
Posts: 1,127
Threads: 136
Joined: Feb 2012
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) .
Posts: 6,267
Threads: 182
Joined: Sep 2011
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.
Posts: 1,127
Threads: 136
Joined: Feb 2012
thanks Shawn,
I must get that php course out one day.
Posts: 3,491
Threads: 106
Joined: Mar 2010
PHP Code:
get_component('sidebar-'.get_page_slug(false));
...so that it doesn't echo the slug.
Posts: 6,267
Threads: 182
Joined: Sep 2011
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
Posts: 3,491
Threads: 106
Joined: Mar 2010
:-)
...or my favorite: get_page_slug(0)
(shorter!)
Posts: 1,127
Threads: 136
Joined: Feb 2012
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.
Posts: 3,491
Threads: 106
Joined: Mar 2010
You could use this:
http://get-simple.info/forums/showthread.php?tid=3102&pid=24159#pid24159
And then change this:
Code:
if (get_component('banner-'.get_page_slug(false)))
by:
Code:
if (component_exists('banner-'.get_page_slug(false)))
Posts: 1,127
Threads: 136
Joined: Feb 2012
all working! Thanks Carlos
Posts: 14
Threads: 6
Joined: Nov 2012
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!