WordPress.org

Ready to get started?Download WordPress

Forums

Embed Category Search Into Page Loop issues (2 posts)

  1. yboss
    Member
    Posted 10 months ago #

    Greetings WP community,
    I've been playing with WP for a while now and I'm trying to create an 'events' page that will post wordpress posts from 'cat=4' or the events category. It is posting fine except for the issue that it is looping the posts over and over again infinitely. Is there a way I can loop this so it shows all category posts but doesn't repeat them? Thanks for all the help everyone!
    -Yuval

    <?php if (have_posts()) :  ?>
                        <?php while (have_posts()) : the_post(); ?>
    
                            <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix post'); ?> role="article">
    
                                <header>
                                    <h2 class="line"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                                </header> <!-- end article header -->
    
                                <section class="post_content clearfix" itemprop="articleBody">
                                  <?php
    query_posts('cat=8');
    while (have_posts()) : the_post();
    the_excerpt();
    endwhile;
    ?>
  2. bcworkz
    Member
    Posted 10 months ago #

    You appear to be running nested loops and are not using wp_reset_query() after using query_posts().

    You should either endwhile the main loop before using query_posts() and a second loop, or use query_posts() before the main loop (without the second loop) if you do not want the normal loop to run at all.

    And don't forget to reset after using query_posts().

Reply

You must log in to post.

About this Topic