Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Remove component from one page not working
#1
Hello,

Following the wiki, I need <?php if (return_page_slug()!='PAGE') get_component('COMPNAME'); ?> in my template.php to disable a component on a certain page.
It is not working for me.
I am trying to disable sidebar on a page.
I am adding the line right after <?php get_component('sidebar'); ?>

Anything I am missing?

Thank you.
Reply
#2
Hi inteq,

If <?php get_component('sidebar'); ?> is in the template, the component will be present on every page. Delete the tag if you don't want it that way.

Regards
English isn't my native language. Sorry for any mistakes you may find.
Reply
#3
Add it instead not after.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
Thank you for reply.
I want the Sidebar component to be present on all pages but on a few selected ones.

So far I discovered that:
if I comment out <?php get_component('sidebar'); ?>
and I add <?php if (return_page_slug()!='index') get_component('Sidebar'); ?>
I will get the Sidebar on all pages BUT index.

Now, if I want to remove the Sidebar from yet another page, my logic tells me that I should add another:
<?php if (return_page_slug()!='another_page') get_component('Sidebar'); ?>

But, if I do that, the Sidebar will be doubled on all pages and will appear once an the pages I want it removed.

One thing that does the trick is:
<?php if (return_page_slug()=='index') get_component('Sidebar'); ?>
<?php if (return_page_slug()=='another_page') get_component('Sidebar'); ?>
This way I will only get the Sidebar on those two pages but it is a bit hard to implement when one has a lot of pages Sad

Did I get it right?
Reply
#5
(2014-10-22, 14:10:04)inteq Wrote: One thing that does the trick is:
<?php if (return_page_slug()=='index') get_component('Sidebar'); ?>
<?php if (return_page_slug()=='another_page') get_component('Sidebar'); ?>
This way I will only get the Sidebar on those two pages but it is a bit hard to implement when one has a lot of pages Sad

You can use the in_array() function to make it more slim.
First you create an array with your "blacklist-slugs", where no sidebar will be shown (or "whitelist-slugs", depends on what is less input):
PHP Code:
$noSidebar = array('page_without_sidebar1','page_without_sidebar2','page_without_sidebar3'); 
Then you check, the slug and output the sidebar:
PHP Code:
if( !in_array(return_page_slug(), $noSidebar) ) {
get_component('Sidebar');

Not tested, but it should work like this.
Reply
#6
@moped Thank you!
It works like a charm.
Exactly what I wanted.
Reply
#7
You can always make use of additional customfield plugin, and control the component from within page options just by checking what is the dropdown or checkbox state on the page.
Addons: blue business theme, Online Visitors, Notepad
Reply




Users browsing this thread: 3 Guest(s)