WordPress.org

Ready to get started?Download WordPress

Forums

Creating a different Sidebar for different pages (6 posts)

  1. nontechblogger
    Member
    Posted 4 years ago #

    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?

  2. 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 } ?>
  3. nontechblogger
    Member
    Posted 4 years ago #

    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.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    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).

  5. 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.

  6. nontechblogger
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic