• PhpcoSqsil

    (@infoservicos)


    I am trying to call a different sidebar, according to the category where the post is inserted through the single.php template.
    In single.php template, I replaced the snippet

    <?php include (TEMPLATEPATH. '/ sidebar_single.php');>

    with this code:

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      $args = array(
        'include' => $cat,
        'hide_empty' => 0
        );
      $categories = get_categories($args);
      if ( ($cat == 3) || ($categories[0]->category_parent == 3) ) {
        include(TEMPLATEPATH . '/includes/sidebar/sidebaranimals.php');
        } elseif ( ($cat == 4) || ($categories[0]->category_parent == 4) ) {
        include(TEMPLATEPATH . '/includes/sidebar/sidebarart.php');
        } else {
    	include( TEMPLATEPATH . '/sidebar_single.php' );
      	}
    }
    ?>

    but when I open a post in a specific category their sidebar does not appear…
    I know this code works in archive.php, but I need to open a different sidebar according to different categories through the single.php file.

    My permanent link is set to: /%category%/%postname%/

    What am I doing wrong?

    Please help!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Different sidebar according to different categories through the single.php’ is closed to new replies.