Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a page with the slug blog. Mysite.com/blog correctly renders from the template file page-blog.php. However, it does not execute footer code from my theme that's conditioned on is_page('blog'), nor does it have an "Edit Page" link in the Admin bar.

I also have a custom post type called blog, but this page doesn't execute code for is_post_type_archive('blog') either. In the admin bar, there is no "Edit Category" link or "Edit [Anything else]".

This is the info the WP Debug plugin gives me when I load the page:

Request:
blog

Query String:
pagename=blog

Matched Rewrite Rule:
(blog)(/[0-9]+)?/?$

Matched Rewrite Query:
pagename=blog&page=

What could be the problem?

share|improve this question
    
First: Please go to your open answers and start marking solved Qs or comment on the answers. With 53% accept rate most people won't answer your Qs anymore. Second: var_dump($GLOBALS['wp_query']). –  kaiser Aug 23 '11 at 17:06
1  
Does your template file use query_posts without wp_reset_query? –  Chris_O Aug 23 '11 at 18:31
    
It does use a secondary loop, and that is the cause of the problem—however, neither wp_reset_query() nor wp_reset_postdata() solve it. After the query and reset(s), var_dump($GLOBALS['wp_query']) still show the last post of the secondary loop. –  supertrue Aug 24 '11 at 21:46
add comment

1 Answer

up vote 0 down vote accepted

The problem was due to a secondary loop in the page—before this loop, the page knows it's a page; but after the loop (and in the footer, where the Admin Bar and my code would be rendered), the page thought it was the last post of the secondary loop.

Neither wp_reset_query() nor wp_reset_postdata() worked; I am guessing this has to do with the fact that I use $wp_query as the name of the secondary loop (so that I could use the loop.php template file to display the posts). Here's the code that worked:

$temp_query = clone $wp_query; 

$wp_query = new WP_Query( 'post_type=publication&posts_per_page=5' );

get_template_part( 'loop' );
/* get_template_part( 'loop' ) only seems to work if the query is in $wp_query */

$wp_query = clone $temp_query; ?>

Here's the link in the codex that the clone $wp_query technique comes from: http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_2

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.