Forums

[resolved] Query_posts + header = headache (5 posts)

  1. crimsonjack
    Member
    Posted 1 year ago #

    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; ?>
  2. Ivovic
    Member
    Posted 1 year ago #

    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.

  3. crimsonjack
    Member
    Posted 1 year ago #

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

    Also found this post from someone with the same problem.

  4. crimsonjack
    Member
    Posted 1 year ago #

    I'm still having trouble with this.

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

  5. crimsonjack
    Member
    Posted 1 year ago #

    Ahh, there it goes.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic