WordPress.org

Forums

Different Sidebar for Particular Category (4 posts)

  1. Digit4L
    Member
    Posted 7 years ago #

    I like to use different sidebar for a particular Category 1

    Already I have edited the template, I am using

    l_sidebar.php & r_sidebar.php for home.php

    l_sidebar1.php & r_sidebar1.php for index.php

    Now I need to add

    l_sidebar3.php & r_sidebar3.php for a particular category.

    I edited the index.php

    Original Code

    <?php include(TEMPLATEPATH."/l_sidebar1.php");?>
    
    <?php include(TEMPLATEPATH."/r_sidebar1.php");?>

    Edited Code

    <?php
      if ( in_category('1') ) {
      include(TEMPLATEPATH."/l_sidebar2.php');
    
      } else {
      include(TEMPLATEPATH."/l_sidebar1.php');
    
      }
    ? >
    <?php
      if ( in_category('1') ) {
      include(TEMPLATEPATH."/r_sidebar2.php');
    
      } else {
      include(TEMPLATEPATH."/r_sidebar1.php');
    
      }
    ? >

    and same goes for category 2, 3, 4 .. so on ..

  2. Chris_K
    Member
    Posted 7 years ago #

    Err, what's the question? What's not working?

    And hey, have you seen Category_Templates yet?

  3. Digit4L
    Member
    Posted 7 years ago #

    When I tried the above code there was error

    Other possible way, it worked,

    I tried to recall the code as per
    http://codex.wordpress.org/Template_Tags/in_category

    <?php if ( in_category('') ): ?>
    // PHP or HTML Code
    <?php endif; ?>

  4. Digit4L
    Member
    Posted 7 years ago #

    Got Some Error in PHP Code

    <?php if ( in_category(1) || in_category (3) || in_category (5) ) {
    echo '<center>HTML Code 1</center>';
    } else {
    echo '<center>HTML Code 2</center>';
    }
    ?>

    Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in //public_html/wp-content/themes/default/l_sidebar1.php on line 43

    IF I use like below one : No Error

    <?php if ( in_category('1') || in_category('3') || in_category('5') ): ?>
    <center>HTML Code 1</center>
    <?php endif; ?>

    <center>HTML Code 2</center>

    Please anyone correct the Code ...

Topic Closed

This topic has been closed to new replies.

About this Topic