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 defined several page templates on my site http://178.21.128.82/. When I set my pages to use one of these page templates, wordpress seems to stop treating it as a page:

  • It is not accepted in the is_page() conditional tag
  • The body class "page" is not present (instead its showing "home").

Only when I use the default page template for my pages they are truly treated as a page by wordpress.

Anyone got a clue what´s going on?

Thanks!

Added:

query_posts('meta_key=wpfp_favorites&orderby=meta_value');

if ( have_posts() ) : while ( have_posts() ) : the_post();
    $start = get_post_meta($post->ID, '5Start', true);
    $stop = get_post_meta($post->ID, '6Slutt', true);

    if(is_active($start, $stop)) { 
        $offer = print_offer($post->ID, $start, $stop);
        echo $offer;
    }

endwhile;
endif;
share|improve this question
    
Most likely you are messing up main Loop, typical reason is wrong usage of query_posts(). Please add code from template that has this issue. –  Rarst Oct 8 '10 at 12:59
    
added some code –  Espen Arnoy Oct 8 '10 at 13:08
    
I think I figured it out. I was messing up with query_posts() –  Espen Arnoy Oct 8 '10 at 13:39
add comment

1 Answer

up vote 1 down vote accepted

Thought so...

You are using query_posts() and this nukes native page's loop and replaces all relevant data with your query. Since your query isn't for page - your page is no longer treated as such.

Always use get_posts() or new WP_Query object for secondary loops.

See When should you use WP_Query vs query_posts() vs get_posts()?

share|improve this answer
    
can´t wp_reset_query() do the job? –  Espen Arnoy Oct 8 '10 at 13:46
    
Not sure, but doesn't matter. It is not meant and should not be used for secondary loops (ever). It makes sense to use right function from the start rather than trying to fix inherently broken approach. –  Rarst Oct 8 '10 at 13:53
    
What do you mean by secondary loops? Any loops outside index.php? –  Espen Arnoy Oct 8 '10 at 14:01
    
Any Loop other than what WordPress creates internally for every page (based on requested URL). Even if you are not querying or displaying anything at all there is still main Loop working in background. The purpose of query_posts() is to change parameters of that Loop. –  Rarst Oct 8 '10 at 14:12
    
OK, thanks for explaining –  Espen Arnoy Oct 10 '10 at 15:19
add comment

Your Answer

 
discard

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