Topic: Display components in specific page only.

Hello,

How could I make some components display in only some pages instead of all?

Thanks.

Re: Display components in specific page only.

You can insert in your template something like:

<?php if (return_page_slug()=='thatpage') get_component('thatcomponent'); ?>

(replace thatpage by your page identifier (slug) and thatcomponent by your component id.)

...Or you could use the DynPages plugin.

Re: Display components in specific page only.

Thank you but I want the components to be on the sidebar, plus I have a lot of pages in my website.

4 (edited by Carlos 2012-02-08 15:28:51)

Re: Display components in specific page only.

If you give every component the same id as their corresponding page slugs, you can insert this in the sidebar:

<?php get_component(return_page_slug()); ?>

That is, a page with slug my-page would display component with name my-page (if that component exists).

Re: Display components in specific page only.

I want to have one conponent for like twenty pages.

Re: Display components in specific page only.

Do those pages have something in common? (same parent page, or some string in the page slug, ...)

If not, something like

<?php 
if (in_array(return_page_slug(),array(
    'slug1'
    ,'slug2'
    ,'slug3'
    // ...
    ,'slug20'
    ))) get_component('componentname');
?>

might work (not tested).

Re: Display components in specific page only.

Thank you.

Same parent actually.

Re: Display components in specific page only.

Then it's easier:

<?php if (get_parent(0)=='parentpage') get_component('componentname'); ?>

9 (edited by JoeyDown 2012-02-08 18:01:46)

Re: Display components in specific page only.

Great, thanks. I figured it out and worked perfectly!!

Re: Display components in specific page only.

my question to this topic is that how would i have a topic header in the sidebar identified as per page then the content that i want in that sidebar ?

Re: Display components in specific page only.

leonku wrote:

my question to this topic is that how would i have a topic header in the sidebar identified as per page then the content that i want in that sidebar ?

If I understood what you're asking, get the Exec-PHP plugin and put this in the sidebar component.

<?php get_page_title(); ?>