WordPress.org

Ready to get started?Download WordPress

Forums

[closed] How to show sidebar on some posts and not others? (9 posts)

  1. glenncvance
    Member
    Posted 4 years ago #

    I found this code -

    <?php $sidebar = get_post_meta($post->ID, "sidebar", true);
    get_sidebar($sidebar);
    ?>

    for showing a particular sidebar per post using custom fields, which is good, but is it possible to show a sidebar on some posts and not others? And if so, how can I do that? Thanks.

  2. jlg371
    Member
    Posted 4 years ago #

    I think that about the best you can hope for is the use of an exclude plugin. There is one in perticular that will add a small drop down to your widgets that will ask what pages to show rthis widget on. I cannot remember the exact plugin right now but its something like exclude pages or something. I use it alot for sites that I build when the customer wants to have different side bar items on one page and different ones on another. You can set it to say that the widgets do not show on page id's =s whatever pages you dont want them to show on. Hope this helps and maybe someone will chime in with a better option.

  3. dougnbr
    Member
    Posted 4 years ago #

    Not sure this is what you had in mind, but using your example with custom fields, just add an 'if', so that if the sidebar custom field == 'none', then don't display any sidebar...

    <?php $sidebar = get_post_meta($post->ID, "sidebar", true);
    if ($sidebar != 'none'){
     get_sidebar($sidebar);
    }
    ?>
  4. glenncvance
    Member
    Posted 4 years ago #

    Thanks everybody. I'll give that a try.

  5. Zarla
    Member
    Posted 4 years ago #

    How do you get to the sidebar custom field?

  6. crisjb
    Member
    Posted 4 years ago #

    Zarla, you would add the custom field "sidebar" in the post editor page. It's below the post text field. You simply need to create the custom field sidebar and give it a value of "none". That's all there is to it. Here's more info: codex.wordpress.org/Custom_Fields

  7. Eseotips
    Member
    Posted 4 years ago #

    thanks for every body i will try it

  8. madivad
    Member
    Posted 4 years ago #

    Couldn't you just select a different template for the page you want without a sidebar? You've probably already got a template for a main page without sidebar and you just select that at the time of creating it. No additional fields or coding required.

  9. mrmist
    Forum Janitor
    Posted 4 years ago #

    Closing due to spam influx. Sorry if this is not resolved, please post a new thread if not.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags