WordPress.org

Ready to get started?Download WordPress

Forums

Embed Category Search Into Page Loop issues (2 posts)

  1. yboss
    Member
    Posted 1 year 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. alchymyth
    Forum Moderator
    Posted 1 year ago #

    use WP_Query() http://codex.wordpress.org/Class_Reference/WP_Query

    <?php
    $events_posts = new WP_Query('cat=8');
    while ($events_posts->have_posts()) : $events_posts->the_post();
    the_excerpt();
    endwhile;
    wp_reset_postdata();
    ?>

    (not tested)

Topic Closed

This topic has been closed to new replies.

About this Topic