different sidebar per category
-
Hi I want to create a different sidebar for a category.
I’ve created category-80.php which fetches sidebar80.php (<?php get_sidebar80(); ?>) to display a separate sidebar for category 80 and it works fine.
Now I would like to display sidebar80 for when a single post is displayed that falls under category 80.
I’ve tried reading Conditional Tags and Template Tags but I’m not smart enough.
Someone please shed light. Many thanks in advance.
-
Here’s a plugin that might possibly work
http://maketecheasier.com/wordpress-plugins/wordpress-widget-changer
I haven’t tried it yet, so I can’t tell you for sure if it will fit your needs.
There’s also a plugin called Page Sidebars, but as the name suggests, it’s page related.
thats not really what im looking for but thanks anyway gestroud. I wanna do this without a plugin, this post seems promising but I still don’t get it unfortunately.
Do you have a special personal function defined in your WP like this:
php get_sidebar80()Otherwise that will not work. To include files that are not defined in the WP core files you should use:
<?php include (TEMPLATEPATH . '/sidebar80.php'); ?>And read again that Conditional page… there is in_category and there is is_category.
HI,
try put this code in your category template where you want the side bar:
<?php if ( (is_category('80')) { include(TEMPLATEPATH . '/sidebar80.php'); } elseif ( (is_category('81')) { include(TEMPLATEPATH . '/sidebar81.php'); } else { include(TEMPLATEPATH . '/sidebar.php'); } ?>you can add as much elseif you want.
hope this helps to you.
nair, that does NOT address the OP’s request:
Now I would like to display sidebar80 for when a single post is displayed that falls under category 80.
ops, you are right! i miss the single page request!!! i’m going to correct the code!
code to put in the single page where you want the sidebar:
<?php $post = $wp_query->post; if ( (in_category('80')) { include(TEMPLATEPATH . '/sidebar80.php'); } elseif ( (in_category('81')) { include(TEMPLATEPATH . '/sidebar81.php'); } else { include(TEMPLATEPATH . '/sidebar.php'); } ?>well this is working for me…
Hi Nair, followed your instructions and I am receiving this error:
Parse error: syntax error, unexpected ‘{‘ in /home/website/public_html/temp/wp-content/themes/mimbo2.2/single.php on line 5
What did I missed? Thanks
How should we know what is on line 5 in your theme?
If you want an answer paste your single.php to http://wordpress.pastebin.ca
Hi, sorry. here it is:
1 <?php get_header(); ?>
2
3 <?php
4 $post = $wp_query->post;
5 if ( (in_category(‘8’)) {and the whole template for single.php is here:
http://wordpress.pastebin.ca/921904Thanks a lot
Should be:
if (in_category('8'))– only one bracket between if and in!
absolutely wonderful. Am now deep into using Conditionals now as a result. As with most stuff I learned with WordPress (or php / mysql for that matter), all I needed was a working example to get started making my own stuff.
Thank you so much.
Thanks a lot moshu, its working now.
The topic ‘different sidebar per category’ is closed to new replies.