0

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;
3
  • 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
    Commented Oct 8, 2010 at 12:59
  • added some code
    – Espen Arnoy
    Commented Oct 8, 2010 at 13:08
  • I think I figured it out. I was messing up with query_posts()
    – Espen Arnoy
    Commented Oct 8, 2010 at 13:39

1 Answer 1

1

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()?

4
  • can´t wp_reset_query() do the job?
    – Espen Arnoy
    Commented Oct 8, 2010 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
    Commented Oct 8, 2010 at 13:53
  • What do you mean by secondary loops? Any loops outside index.php?
    – Espen Arnoy
    Commented Oct 8, 2010 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
    Commented Oct 8, 2010 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.