WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query_post Impacts is_page() ? (6 posts)

  1. tflight
    Member
    Posted 7 years ago #

    I have a page (not post) that I'm creating on my site. The purpose of that page is to display three "blocks", each with a list of the 10 most recent posts in a specific category.

    So I created a template specifically for that page. In the template I use get_header() to grab the top of my site. Then I use the query_posts function and the rewind_posts function to create each "block". So far so good, all of this works as intended.

    However at the bottom of the page I want to do something special if the user is looking at that any page (not post). The bottom is built using the get_footer() function. In my footer template I have an if statement that checks to see if we are looking at a page with the is_page function.

    The is_page function seems to break when I have used the query_posts function in the page template. If I just use a regular Loop without any query_post function the footer correctly identifies the page as a page via the is_page function and it does what I want.

    However as soon as I use the query_post function on a page, the is_page function no longer returns true. Is there something I'm missing? After I enter The Loop for the last time in the page template I've tried calling rewind_posts again thinking that perhaps something needed to be reset, however is_page still evaluates to false when viewing that page.

  2. Kafkaesqui

    Posted 7 years ago #

    You'll have to reset properties of the WP_Query object to resolve this, but that's ok because you can do this in your template after the last instance of query_posts:

    <?php
    $wp_query->is_category = false;
    $wp_query->is_archive = false;
    $wp_query->is_page = true;
    ?>

    The above should take care of your problem if you are using query_posts to call posts of specific categories, but basically the properties under $wp_query for this coincide with the Conditional tags.

  3. tflight
    Member
    Posted 7 years ago #

    Thanks, Kafkaesqui! I am using query_posts just to call specific categories so that should work great.

    For future reference, if I need to check for a specific page in the footer, is there a way to reset the properties of the wp_query object to know what page ID I'm using rather than just that it is indeed a page?

    I suppose I could just create my own new variable in the page template and check for that in the footer as well, but that wouldn't be as fun. :)

  4. Kafkaesqui

    Posted 7 years ago #

    "is there a way to reset the properties of the wp_query object to know what page ID I'm using rather than just that it is indeed a page?"

    Resetting the conditional properties of the WP_Query object just touches on the query 'page' type in general. So, no. But I'll dig a bit and see if there's a way around having to do this the less fun way. :/

  5. tflight
    Member
    Posted 7 years ago #

    No problem, don't worry about it. I'm just thinking ahead to the possibility I might need it someday, but right now I don't.

  6. Jeff
    Member
    Posted 7 years ago #

    I think I may have described what you are seeking in this topic:

    http://wordpress.org/support/topic/91228

    basically copying the page query into a temporary location before all the loops and returning it after.

Topic Closed

This topic has been closed to new replies.

About this Topic