Support » Fixing WordPress » Variable Sidebar Using Conditional Tags

  • Im not a PHP guru, but I am having a good time trying to figure things out. Here’s the rub: My goal is to have a different sidebar for each page on my blog. I am trying to place several divs inside “Conditional Tags” which call different sidebars according to each page but I’m not having much luck. If someone could give me the proper markup or tell me a better way of making this happen, please inform.

    I want to place the following:

    <div class="SR">
    <div class="Twitter">
    <h2><img src="image path"></h2>
    <ul id="twitter_update_list"></ul>
    <script type="text/javascript" src=""></script>
    <script text="text/javascript" src=""></script>
    <div class="Flickr">
    <h2><img src="image path"></h2>
    <ul><li><script type="text/javascript" src=";count=6&amp;display=latest&amp;name=0&amp;size=square&amp;raw=1"></script></li>
    <div class="Categ">
    <h2><img src="image path"></h2>
    <ul><? netflix(); ?></ul>

    into the following Conditional Statement to render variable sidebar content:

    <!-- begin sidebar -->
    <div id="sidebar">
    // let's generate info appropriate to the page being displayed
    if (is_home()) {
            // we're on the home page, so let's show a list of all top-level categories
            echo "<ul>";
            echo "</ul>";
    } elseif (is_category()) {
            // we're looking at a single category view, so let's show _all_ the categories
             echo "<ul>";
            echo "</ul>";
    } elseif (is_single()) {
            // we're looking at a single page, so let's not show anything in the sidebar
    } elseif (is_page()) {
            // we're looking at a static page.  Which one?
            if (is_page('About')) {
                 // our about page.
                 echo "<p>This is my about page!</p>";
            } elseif (is_page('Colophon')) {
                 echo "<p>This is my colophon page, running on WordPress " . bloginfo('version') . "</p>";
            } else {
                  // catch-all for other pages
                  echo "<p>Vote for Pedro!</p>";
    } else {
            // catch-all for everything else (archives, searches, 404s, etc)
            echo "<p>Pedro offers you his protection.</p>";
    } // That's all, folks!
    <form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="s" id="s" size="15" />
    <input type="submit" value="<?php _e('Search'); ?>" />
    <!-- end sidebar -->

    This can also be found at

Viewing 1 replies (of 1 total)
  • Actually, let me clarify a bit more, I would like the provided sidebar content used for the “home” page. I would also like to render more divs within if (is_page('page name')) similar to that of the home page. If anyone could just show me the correct way to stick that in there and make it work properly, that would be amazing…

Viewing 1 replies (of 1 total)
  • The topic ‘Variable Sidebar Using Conditional Tags’ is closed to new replies.