• I have attempted to use the Multiple Loop examples, as well as combed through the Loop codex page. I have tried various things like setting up two loops but I can’t seem to get posts to list in the header without messing up the index page.

    The code below has always worked for me throughout my other templates I’ve worked with, but I have never tried listing posts in the header section. Is there any way to do it without creating another loop? I can’t seem to get two loops to function properly after following the instructions multiple times.

    I want to basically have a “Featured” section at the top of the blog but listed in plain text with links.

    <?php query_posts('category_name=jihad-watch&showposts=1');
    while (have_posts()) : the_post();
      // do whatever you want
    ?>
    <h2 class="jwEntryTitle"><a target="_blank" href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2><br />
    <p><?php print string_limit_words(get_the_excerpt(), 100); ?>...</p>
    <?php
    endwhile;
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter user65

    (@user65)

    This seemed to work for me:

    <?php
    $featuredPosts = new WP_Query();
    $featuredPosts->query('showposts=5&cat=3');
    while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
    <div class="meta">
    By <?php the_author() ?>
    </div>
    <div class="storycontent">
    <?php the_excerpt(); ?>
    </div>
    <?php endwhile; ?>

    That’s a good solution.

    Putting wp_reset_query(); after that first example would probably solve the problem, but your solution is better.

    I’m using the above code inside of PHP Code Widget, and it works fine as is, but as you can see blow, I tried to get it to also show the tags, but they don’t display, even in the source code. And it’s definitely in there.
    Doesn’t do a thing, even if above the endwhile at the end.
    Anyone know what’s going on?
    Thanks

    <?php
    $featuredPosts = new WP_Query();
    $featuredPosts->query('showposts=5&cat=3');
    while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
    <div class="meta">
    By <?php the_author() ?>
    </div>
    <div class="storycontent">
    <?php the_excerpt(); ?>
    </div>
    <?php endwhile; ?>
    <?php the_tags(); ?>

    Thanks for pointing out wp_reset_query – just helped me resolve an issue where after a custom query, my single.php had the category of the featured post cached, rather than the category of the post on single.php.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘List Posts in Header.php’ is closed to new replies.