Support » Themes and Templates » Creating a different Sidebar for different pages

  • I’m creating a website with static pages and a blog. I’d like to have a different Sidebar for the blog from the static pages. How do I do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Mark Ratledge


    Forum Moderator

    Customizing Your Sidebar « WordPress Codex.

    And/or, something like this in sidebar.php:

    <?php if (is_page('2')) { ?> html here
    <?php } elseif (is_page('4')) { ?>other html stuff here
    <?php } else (is_page('6')) { ?> still more html stuff here
    <?php } ?>

    Thanks, I read that Codex page but it didn’t solve. I understand about calling different sidebars. The problem was I didn’t know which file called for the sidebar, as I don’t see the page files in my theme directory. All I have it index.php. Can I post the content of index.php and someone can tell me what I need to do?

    As for your second option, I’m guessing that makes the sidebar to call for which sidebar depending on the page. The problem is I don’t know how to call for those pages.



    Forum Moderator

    Can I post the content of index.php

    Please don’t. For larger blocks of code, use the WordPress pastebin and post the pastebin url here. It makes life easier for everyone.

    The function get_sidebar() calls your sidebar file(s).

    Moderator Mark Ratledge


    Forum Moderator

    The page numbers in my example are the page ID numbers for dynamic pages generated by wordpress; they’re not static pages in the template directory. You’re thinking of old style static html pages, with a file for each page.

    My code example is code that goes in sidebar.php to call different html according to the page being generated. If you’re “About” page is page ID 2, then the code displays the html under the “if” statement. Page ID 4 means the second elseif statement.

    Tarski has a sidebar.php. Look in it and also look in index.php and single.php, etc., to see how the sidebar is called.

    Thanks guys, Tarski had an option I was able to do this without editing files. I really need to learn WordPress.. if anybody knows a good tutorial source on basics and theme customization, please let me know! Codex isn’t always user friendly.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Creating a different Sidebar for different pages’ is closed to new replies.