Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Components specific to the page - How?
#1
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
Reply
#2
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'); ?>
Reply
#3
Just use the slug in the component name when calling it.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
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) .
Reply
#5
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
thanks Shawn,

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

...so that it doesn't echo the slug.
Reply
#8
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
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#9
:-)

...or my favorite: get_page_slug(0)
(shorter!)
Reply
#10
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.
Reply
#11
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)))
Reply
#12
all working! Thanks Carlos
Reply
#13
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!
Reply




Users browsing this thread: 2 Guest(s)