DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Variable Sidebar

  • submit to reddit
        <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'); ?>" />