• looking to have a dynamic sidebar, but sidebar template doesn’t seem to realize what page it’s being displayed on. My code is correct and I’ve tried multiple variances:

    <?php
    if (is_page('72'))
    {
        echo "page id 72";
    }
    ?>
    <?php
    if (is_page('content'))
    {
        echo "page named content";
    }
    ?>

    the two examples above do not parse at all; i.e. echoed text does not appear.

    <?php
    if (is_page())
    {
        echo "any page at all";
    }
    else
    {
        echo "this is NOT a page";
    }
    ?>

    the above example returns “this is not a page” on all pages, as well as home. All this code is being tested in the sidebar template, in the same wordpress theme I am using.

    I fear this may be an unfixable bug of some sort. What I may do instead to combat it is create a new template for every sidebar variance I require (i.e. multiple sidebar templates), then call specific versions on a per-page basis. Can anyone instruct me on how to do this?

    thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try not using the single quotes around the page number?

    <?php
    if (is_page(72))
    {
        echo ('page id 72');
    }
    ?>
    
    <?php
    if (is_page('content'))
    {
        echo ('page named content');
    }
    ?>

    That’s the first thing I’d try… and then be sure you are getting to those pages, of course. When you are testing, what is the page url you are on?

    hmmm… I use if (is_page()) all the time in the sidebar.

    what version of WP are you using AND are you actually using pages? or posts?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_page not working on sidebar – how do I add a new template?’ is closed to new replies.