• Resolved crimsonjack

    (@crimsonjack)


    I’m trying to use query_posts to show a list of recent additions in the header. I got this working fine, except for one major issue. For some reason, after listing the 4 most recent articles, everypage lists these 4 articles.. So I’m guessing that somehow the Query_posts in the header is effecting the content of the whole page.

    Is there a way to stop this?
    Does the content / entry loop have to be before any query_posts? (like how the sidebar is setup?)

    http://desunoto.com/otaku/

    This is what I’m using in my header.

    <?php query_posts('showposts=4');?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div class="contents">
    <strong><a title="View this post" href="<?php the_permalink() ?>">
    <?php the_title() ?>
    </a></strong>
    </div>
    
    <?php endwhile; endif; ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • there’s a default query in place for each “view”… when you run the query in the header, you intercept that before the page template can get its hands on the default query.

    the solution is to use a custom query variable which you’ll find under “multiple loops” on the query_posts codex page – or to use something like get_posts which is actually a lighter way to go anyway.

    Thread Starter crimsonjack

    (@crimsonjack)

    Thanks for pointing me in the right direction.
    I’ll give it a shot.

    Also found this post from someone with the same problem.

    Thread Starter crimsonjack

    (@crimsonjack)

    I’m still having trouble with this.

    What code should i use for the archive?
    have tried multiple things with no luck.

    Thread Starter crimsonjack

    (@crimsonjack)

    Ahh, there it goes.

    Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Query_posts header = headache’ is closed to new replies.