WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Variable Sidebar Content (2 posts)

  1. tab0429
    Member
    Posted 5 months ago #

    Hello, I'm very new to WordPress themes and I am trying to design my own. I don't want to have any widgets on my sidebar, I only want a color bar to show up on every page, I want the color to change depending on the category being viewed but I'm having trouble writing the code for this, I keep getting error after error...

    Here is what I would like to show on most pages:

    <div class="bar1"></div>
    	        <div class="bar2"></div>
    	        <div class="bar3"></div>

    Then for category 1 I want to show <div class="bar1A"></div>, for category 2 <div class="bar2A"></div>and category 3 <div class="bar3A"></div>

    I tried creating 2 different sidebars but had no success either. I tried the code below:

    <div id="bar">
    
    <?php if (is_category( '1' ) ) { ?>
    
    	        <div class="bar1A">
    	        </div>
    
    } <?php if (is_category( '2' ) ) { ?>
    
    	        <div class="bar2A">
    	        </div>
    
    } <?php if (is_category( '3' ) ) { ?>
    
    	        <div class="bar3A">
    	        </div>
    
    } <?php elseif {
    
    	        <div class="bar1"></div>
    	        <div class="bar2"></div>
    	        <div class="bar3"></div>
    
     ?>
    
     </div>

    But I only get errors... I change somethings here and there and then get no sidebar at all, or parse errors...

    Can anyone help me, please?

  2. tab0429
    Member
    Posted 5 months ago #

    I figured it out:

    <?php if ( in_category( '1' ) ) {
    
    echo '<div id="bar"><div class="bar1A"></div></div>';
    
    } elseif ( in_category( '2' ) ) {
    
    echo '<div id="bar"><div class="bar2A"></div></div>';
    
    } elseif ( in_category( '3' ) ) {
    
    echo '<div id="bar"><div class="bar3A"></div></div>';
    
    } elseif ( is_category() ) {
    
    	        echo '<div id="bar"><div class="bar1">
    	        </div>
    	        <div class="bar2">
    	        </div>
    	        <div class="bar3">
    	        </div></div>';
    
    }
    ?>
    <?php endif;?>

Reply

You must log in to post.

About this Topic

Tags

No tags yet.