Forums

Dynamic sidebars and css (6 posts)

  1. bmohr
    Member
    Posted 1 month ago #

    I would like to change the background color of my sidebar depending on which page the user is on. Can someone please tell me how to do this?

    This is my sidebar.php code:

    <div id="sidebar">
    		<ul>
    
        <?php if (is_page('consumer-products')) { ?>
    
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-consumer-products') ) ?>
    
        <?php } elseif (is_page('small-business-products')) { ?>
    
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-small-business-products') ) ?>
    
        <?php } else { ?>
    
        <?php } if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(sidebar-main) ) ?> 
    
    </ul>
    	</div>

    This is my functions.php code:

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar-consumer-products',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));
    register_sidebar(array('name'=>'sidebar-small-business-products',
    'before_widget' => '',
    'after_widget' => '',
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ));?>
  2. esmi
    Member
    Posted 1 month ago #

    Is it just for those two pages? A link to your site would help...

  3. bmohr
    Member
    Posted 1 month ago #

    No. There's many more pages. The above code are samples of the 2 pages that I need to figure out how to change the css style for. See the 2 links below.

    consumer products:
    http://www.mohrdesigns.com/consumer-products

    small business products:
    http://www.mohrdesigns.com/consumer-products

    I need to figure out how to get the sidebar background color to change depending on if the user is on the consumer product pages or the small business products pages????

    Thanks in advance for any help!

  4. esmi
    Member
    Posted 1 month ago #

    Try adding:

    'before_widget' => '<div class="consumer">',
    'after_widget' => '</div>',

    and then style on the new consumer class. If that works, amend the others similarly.

  5. bmohr
    Member
    Posted 1 month ago #

    Here's what I'm getting:
    http://www.mohrdesigns.com/small-business-products/overview

    It's still trying to show the other sidebar...below the new style??? Is this because I have this at the end of my sidebar page:

    <?php } else { ?>
    
        <?php } if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(sidebar-main) ) ?>

    Any suggestions?

  6. esmi
    Member
    Posted 1 month ago #

    If you want each sidebar to show by itself, try:

    <div id="sidebar">
    <ul>
    <?php
    if (is_page('consumer-products')) {
    	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-consumer-products') ) :
    	endif;
    }
    elseif (is_page('small-business-products')) {
    	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-small-business-products') ) :
    	endif;
    }
    else {
    	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(sidebar-main) ) ?>
    	endif;
    }
    ?>
    </ul>
    </div>

Reply

You must log in to post.

About this Topic

Tags

No tags yet.