• Hey all. I’m setting up a site as more of a CMS with a blog page on the back end. The page links are running in a menu across the top, and for most pages I’ve managed to hide the sidebar(s) based on the page. I’m doing this with this bit of code in the header:

    <?php if (is_page('blog') || is_single()){ ?>
    <style type="text/css">
    #content
    {
      font-size:15px;
      float:left;
      width:590px;
      padding:0 0 0 1em;
    }
    </style>
    <?php } else { ?>
    <style type="text/css">
    #sidebar
    {
    	display:none;
    }
    </style>
    <?php } ?>

    What that’s doing is hiding the side bar if the page is not a blog or single post page, and showing it if it is. Currently this is working on the “static” pages and the single post pages – but not on the main blog page.

    Here’s where I’m running into trouble: I set the blog page up as “Blog”, and the slug is “blog”. However, when I do go to the blog page, the slug is the name of my current post: “sample-post”.

    Is there a way to check for the main blog page? Thanks for your help!

Viewing 1 replies (of 1 total)
  • is_archive would cover all archive pages but it would also return true on category and tag pages. If you want the sidebar showing on those page, you’ll have to qualify it with something like:

    if(is_archive() &amp;&amp; !is_category() &amp;&amp; !is_tag() {
    [CSS]
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Showing/Hiding sidebar based on page – almost there but need help!’ is closed to new replies.