Page Template, query_posts() breaks is_page()?
-
I’m creating a custom Page template and have run into an apparent interaction between the functions query_posts() and is_page() that I can’t seem to resolve. Haven’t been able to find posts with a similar problem, so here’s a description:
In my custom Page template, I call query_posts() to set up a loop. I want to grab the first 50 posts and display them.
Code, Figure A:
<?php query_posts(‘showposts=50’); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
(*snip* the rest of the loop displays the titles of the posts. it’s a valid loop and works, so I’m leaving that out.)After I finish this loop, sometime later, I call is_page() from the sidebar.php file. I’m customizing the sidebar based on whether or not we’re in a Page.
Code, Figure B:
<?php if ( !is_page() ) { ?>
(we are not in a Page, display x)
<?php } else { ?>
(we are in a Page, display y)
<?php } ?>Now, the strange thing is that the code in Figure B works great, so long as the line:
<?php query_posts(‘showposts=50’); ?>
in Figure A does not exist! If I take the line out, it works, if I put it back in, it doesn’t work and (!is_page()) always equals TRUE, even when we’re in a Page.Does the use of query_posts() change the functionality of is_page() or break it in some way that isn’t documented? Any insight would be much appreciated… I’m stumped.
Thanks…
- The topic ‘Page Template, query_posts() breaks is_page()?’ is closed to new replies.