Forums

[resolved] is_page() needs to meet certain conditions? (5 posts)

  1. Zambrano Sergio
    Member
    Posted 2 years ago #

    I can't get to work my is_page('contact') conditional. It ALWAYS return false.

    I've put it in the footer.php to show the slide-in contact form on any page OTHER than "Contact" page http://seosumo.com/contact since that page already contains a contact form.

    This is my code
    <?php if (!is_page('Contact')) {
    include(TEMPLATEPATH.'/sideform.php');
    } ?>

    I've tried with the following no success:
    -lowercase (as the url shows) 'contact'
    -different if arrangements (if(foo)) :
    -page ID instead of name.
    -is_page() combined with else instead of !is_page()
    -is_page() conditional placed on the page's template instead of footer.

    Nothing worked, so my questions are:
    1) Does is_page() need the page to show 1 page only? no extra loops? (mine loads blog posts in that page too)

    2) Does is_page() need to be called from within the loop?

    WP version is 2.7.1

    Any ideas?

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Using a just installed 2.7.1 blog and the WordPress Default theme, and putting this in the wp-content/themes/default/footer.php

    <?php if (is_page('About')) {
    echo 'this is page 2';
    }
    ?>

    Does cause 'this is page 2' to be displayed ONLY when viewing the About page.

  3. Zambrano Sergio
    Member
    Posted 2 years ago #

    SOLVED:

    When using multiple loops, the is_page('Somepage') doesn't work.

    I just added wp_reset_query() and it works like a charm.

    <?php wp_reset_query();
    if (!is_page('Contact')) {
    include(TEMPLATEPATH.'/sideform.php');
    }
    ?>

    I don't know the extent of the issue, or which of the commands/variables of the secondary loop caused this, but resetting the query worked.

    I hope someone have the specific reason of this, so we can play around the code more freely.

  4. dorian06
    Member
    Posted 2 years ago #

    wp_reset_query(); works great to solve problems :)

  5. rcain
    Member
    Posted 1 year ago #

    thanks for posting Sergio - solved my exact same problem :)

Topic Closed

This topic has been closed to new replies.

About this Topic