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

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.

    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);
    }
    ?>
    Thread Starter glenncvance

    (@glenncvance)

    Thanks everybody. I’ll give that a try.

    How do you get to the sidebar custom field?

    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

    thanks for every body i will try it

    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.

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to show sidebar on some posts and not others?’ is closed to new replies.