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

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
thanks Shawn,

I must get that php course out one day.
PHP Code:
get_component('sidebar-'.get_page_slug(false)); that it doesn't echo the slug.
yeah or you can use return_page_slug()

PHP Code:
function return_page_slug() {

my bad was just copying psuedocode
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix

...or my favorite: get_page_slug(0)
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)))
                        else {
get_component('slideshow');}    ?>
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:

And then change this:

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


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:

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

It worked!

Users browsing this thread: 1 Guest(s)