WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Different Sidebars for Different Pages (10 posts)

  1. KeithStrohm
    Member
    Posted 7 years ago #

    I'm very new to WordPress, and I'm working with a custom template I uploaded. I have two questions:

    1. There are sidebar "widgets" imbedded in the code of the template. Some of them are active and some seem to be placeholders. For example, there is a sidebar that says it is a placeholder for an Aside or for ads. However, when I create a sidebar page, it doesn't show up anywhere on the sidebars of the page.

    How do I activate those placeholder sidebars?

    2. Is it possible to have different sidebars on different pages? I like all the sidebars on pages I'll use to blog, but not necessarily on other static pages?

    I should mention that my knowledge of coding is virtually nil.

    Thanks,

    Keith

  2. Doodlebee
    Member
    Posted 7 years ago #

    Some of them are active and some seem to be placeholders. For example, there is a sidebar that says it is a placeholder for an Aside or for ads.

    Chances are, you're seeing something like this:

    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else :?>

    then it goes on to show the "placeholder" stuff you're talking about.

    What that line says is "If you have the sidebar widgets plugin activated, then generate the sidebar using the plugin.

    ELSE

    Use the below stuff."

    So if your widgets plugin is on, the "placeholder" stuff will not be seen - not unless you deactivate the widgets plugin.

    Is it possible to have different sidebars on different pages?

    Yes. Just use a conditional. For example, put this at the top of your sidebar.php file:

    <?php if (is_page()) { ?>
    put how you want your sidebar to look here
    <?php } ?>
  3. KeithStrohm
    Member
    Posted 7 years ago #

    Doodlebee,

    Thanks so much for the info! I'll give it a try.

    Keith

  4. KeithStrohm
    Member
    Posted 7 years ago #

    Doodlebee,

    I am indeed seeing what you described in my sidebar php. The thing is, my theme is not listed as one that utilizes the sidebar widgets plugin. Is it still possible to use the sidebar widgets plugin?

    Where can I get that plugin?

    In terms of using a conditional, my coding skills are negligible. I have two more questions:

    You wrote that I should use the following conditional:

    <?php if (is_page()) { ?>

    How do I identify what page I'm setting the conditional for? Do I use the url for that page and place it between the empty parantheses?

    How do you code how you want your sidebar to appear? Is there a manual somewhere that can help me? Or can I copy the code from a sidebar that I want elsewhere?

    Sorry I'm asking these questions, but I am a major noob when it comes to this stuff.

  5. Doodlebee
    Member
    Posted 7 years ago #

    Where can I get that plugin?</em?

    automattic.com. Instructions for use are in the zip file.

    <?php if (is_page()) { ?>

    How do I identify what page I'm setting the conditional for?

    Page ID. In your "Manage" area, each Page you create has a number next to it - that's the Page ID. so, if you want the sidebar to work *only* for, say "Fish" and "Fish" has the ID of "7", then:

    <?php if (is_page('7')) { ?>

    If you want it for *all* pages, then don't put anything in the parenthesis.

    How do you code how you want your sidebar to appear?

    That is basic HTML. The default stuff is in the default template, but to tell you how to code it is something that's *way* beyond the scope of this forum. There's too may variables - you have to know what you want to appear and where you want it - then you code it using HTML.

    Like I said, you can use the default from the default them (sidebar.php) - but to customize it is up to you.

  6. KeithStrohm
    Member
    Posted 7 years ago #

    Doodlebee,

    Thank you...thank you...thank you! I was able to upload and install the sidebar widgets plugin...!!

    Regarding conditionals, if I want my calendar widget to appear on only my blog page, can I set the conditional for that blog page and copy all of the code from the sidebars I do want, eliminating the code for the calendar on that blog page?

    If so, then I don't have to worry about building sidebars from scratch.

    Thanks again, you have been so helpful!

  7. Doodlebee
    Member
    Posted 7 years ago #

    Regarding conditionals, if I want my calendar widget to appear on only my blog page, can I set the conditional for that blog page and copy all of the code from the sidebars I do want, eliminating the code for the calendar on that blog page?

    I think the *best* way to accomplish this is to not use the calendar widget at all. You can't really do conditionals *within* widgets. Well, you could kind of finagle it a bit with CSS and make the *visibility* of the calendar change depending on what page you're on...just set the calendar div to "display:none;" when it comes to certain pages. It'll still show up in your code, but it won't be seen.

    But the better way to do it would be, in your sidebar.php file, right *before* the call to the widget sidebar, just call in the code for the calendar in the conditional. *Then* put in your widget code.

    So on any page you *don't* want the calendar to show up in, it won't - it'll just show the widget sidebar. But when you *do* want it to show, the calendar will appear *before* the widgets do.

    So, it'd be something like:

    <?php if (is_page()) { //nothing here
    } else { ?>
    calendar code here
    <?php } ?>
    
    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else :?>

    Make sense?

  8. KeithStrohm
    Member
    Posted 7 years ago #

    Doodlebee,

    That certaimly does! Thanks so much! I've learned a great deal from you.

    Keith

  9. Steve Bruner
    Member
    Posted 7 years ago #

    doodlebee,

    you rock!
    <?php if (is_page()) { ?> works great. Now I want to expand it and show a particular sidebar if either a specific page OR a post from a specific category is shown.

    I tried this and it didn't work.

    <?php if (is_page(14))elseif (in_category('6')?>

    Any suggestions?

    Thanks
    Steve

  10. hamishtish
    Member
    Posted 7 years ago #

    Hello guys,

    <?php if (is_page('7')) { ?>

    is a great way to do this, but how do I set the if statement for multiple pages istead of just the one '7' page. For example say I want the same sidebar for page 1, 2, 3, and 4.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic