Support » Themes and Templates » Can’t get is_page() tag to work in the sidebar

  • Resolved danielb

    (@danielb)


    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?

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

    Thread Starter danielb

    (@danielb)

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

    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.

    Thread Starter danielb

    (@danielb)

    wp_reset_query() worked.
    Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can’t get is_page() tag to work in the sidebar’ is closed to new replies.