• ghmercado

    (@ghmercado)


    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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Gestroud

    (@gestroud)

    Here’s a plugin that might possibly work

    https://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.

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

    Thread Starter ghmercado

    (@ghmercado)

    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.

    moshu

    (@moshu)

    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.

    nair

    (@nair)

    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.

    moshu

    (@moshu)

    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.

    nair

    (@nair)

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

    nair

    (@nair)

    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…

    bongkph

    (@bongkph)

    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

    moshu

    (@moshu)

    How should we know what is on line 5 in your theme?

    If you want an answer paste your single.php to https://wordpress.pastebin.ca

    bongkph

    (@bongkph)

    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:
    https://wordpress.pastebin.ca/921904

    Thanks a lot

    moshu

    (@moshu)

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

    – only one bracket between if and in!

    Thread Starter ghmercado

    (@ghmercado)

    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.

    bongkph

    (@bongkph)

    Thanks a lot moshu, its working now.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘different sidebar per category’ is closed to new replies.