WordPress.org

Ready to get started?Download WordPress

Forums

different sidebar per category (14 posts)

  1. ghmercado
    Member
    Posted 6 years ago #

    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.

  2. Gestroud
    Member
    Posted 6 years ago #

    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.

    http://www.nexterous.com/scripts/pagesidebar.php

  3. ghmercado
    Member
    Posted 6 years ago #

    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.

  4. moshu
    Member
    Posted 6 years ago #

    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.

  5. nair
    Member
    Posted 6 years ago #

    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.

  6. moshu
    Member
    Posted 6 years ago #

    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.

  7. nair
    Member
    Posted 6 years ago #

    ops, you are right! i miss the single page request!!! i'm going to correct the code!

  8. nair
    Member
    Posted 6 years ago #

    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...

  9. bongkph
    Member
    Posted 6 years ago #

    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

  10. moshu
    Member
    Posted 6 years ago #

    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

  11. bongkph
    Member
    Posted 6 years ago #

    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/921904

    Thanks a lot

  12. moshu
    Member
    Posted 6 years ago #

    Should be:
    if (in_category('8'))

    - only one bracket between if and in!

  13. ghmercado
    Member
    Posted 6 years ago #

    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.

  14. bongkph
    Member
    Posted 6 years ago #

    Thanks a lot moshu, its working now.

Topic Closed

This topic has been closed to new replies.

About this Topic