Forums

display cats and archive on blog only (9 posts)

  1. RSimpson
    Member
    Posted 1 week ago #

    Hi folks,

    Does anyone have a quick and dirty way I can alter my sidebar.php so that categories and archives appear only on my blog and not the pages?

    Cheers,
    Robert

  2. Rhand
    Member
    Posted 1 week ago #

    Remove them from page.php if you have one defined in that particular theme.

  3. RSimpson
    Member
    Posted 1 week ago #

    Hi Rhand,

    I can see <?php get_sidebar(); ?> in there, I don't want to remove the sidebar completely, I just want to remove the categories and archive when people are viewing pages instead of the blog, I still want the pages navigation to show up. Is there a quick if else conditional I can throw around the 2 parts in sidebar.php?

    Cheers,
    Robert

  4. RSimpson
    Member
    Posted 1 week ago #

    Anybody? :)

  5. adam-s
    Member
    Posted 1 week ago #

    You could try something like...

    if (!is_page){

    }

    ...in sidebar.php around the categories and archives code.

  6. wp_guy
    Member
    Posted 1 week ago #

    Yep, you can use the is_page() conditional tag, as long as your sidebar isn't widgetized. Otherwise you'd need to create 2 sidebars (one for your blog and one for the pages).

  7. RSimpson
    Member
    Posted 1 week ago #

    Hi guys,

    I tried the is_page() conditional and the cats and archive disappeared completely. My blog is not the home page, it's the posts page which I set under Settings > Reading.

    Cheers,
    Robert

  8. wp_guy
    Member
    Posted 1 week ago #

    Notice that adam-s' code has an exclamation mark (!) in front of the is_page() (which would be like saying isnt_page() if you know what I mean)...

    if(!is_page()){
         // Your categories and archives
    }

    That would make the categories and archives appear in the home page, in the single post page, etc. Everywhere but the pages (eg. About, Contact, etc.)

  9. RSimpson
    Member
    Posted 1 day ago #

    Sorry it took me so long to reply to this, I'd made a mistake in my own code (daft thing) and !is_page() does in fact work :)

    Mark as resolved! :D

    Cheers,
    Robert

Reply

You must log in to post.

About this Topic