WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Can't get is_page() tag to work in the sidebar (5 posts)

  1. danielb
    Member
    Posted 5 years ago #

    On my site I have a static page called 'archive', it's displayed using the archives.php template. There's a link to this page in the sibedar, and I want to hide this link when a user is on the Archives page.

    I tried using both is_page() and is_page_template() conditional tags without any success. I also tried referring to the page by its name and ID, still without success.

    Here's what I've tried to put in the sidebar:
    <?php if (is_page(64)) { ?>blah-blah<?php } ?>
    <?php if (is_page('archive')) { ?>blah-blah<?php } ?>
    <?php if (is_page_template('archives.php')) { ?>blah-blah<?php } ?>

    None of the above displayed in the sidebar on /archive page.

    Please can you tell me what am I doing wrong?

  2. t31os
    Member
    Posted 5 years ago #

    <?php
    if(is_page('64'))
    { ?>
      blah-blah
    <?php
    }
    elseif(is_page('archive'))
    { ?>
      blah-blah
    <?php
    }
    elseif(is_page_template('archives.php'))
    { ?>
      blah-blah
    <?php
    } ?>

    You were missing the single quotes on the first check. I also formatted the code and put in some else statements..

    Unless you need more then one of those statements to return true and display 2 lots of content if 2 are matched, in which case switch back to IFs only..

  3. danielb
    Member
    Posted 5 years ago #

    This doesn't work as well.
    Are conditional tags supposed to work in sidebar at all?

  4. Justin Tadlock
    Member
    Posted 5 years ago #

    Please can you tell me what am I doing wrong?

    All of those examples should work fine.

    The problem is probably with a query somewhere on your page. Add this to the bottom of your archives.php page template and see if it helps:

    <?php wp_reset_query(); ?>

    Make sure it comes before any calls to the sidebar.

  5. danielb
    Member
    Posted 5 years ago #

    wp_reset_query() worked.
    Thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic