• Hi, I’ve had a look through the twentyten loop but I can’t figure this out at this hour of the night. What is the best way to filter posts by category with the below codeblock? Thanks.

    <h2 class="entryhead"><a href="<?php the_permalink() ?>"><?php the_title(); ?> </a></h2>
    		 <div id="news" class="about"> 
    
             <?php if (have_posts() ) : ?>
             	<?php while (have_posts() ) : the_post(); ?>
                	<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
                            <div class="entry">
                           <?php the_excerpt(); ?> 
    
                             </div>
                             <em class="postedon"> Posted on: <?php the_time('F jS, Y') ?></em>
                            <em class="postedby">by <?php the_author() ?></em>
                             <div class="postmetadata">
                             <?php the_tags('Tags: ', ',', '<br />'); ?>
                              Posted in <?php the_category(', ')?> |
                              <?php comments_popup_link('No Comments »', ' 1 Comment »', '% Comments »'); ?>
                     </article>
                <?php endwhile; ?>
    
                <?php else : ?>
                <h2>Not Found</h2>
              <?php endif ; ?>
    
    		</div><!-- news -->
Viewing 4 replies - 1 through 4 (of 4 total)
  • Try replacing this:

    <?php if (have_posts() ) : ?>

    with this:

    <?php
    global $wp_query;
    query_posts(
       array_merge(
          $wp_query->query,
          array('cat' => 1)  // Replace with your cat id
       )
    ); ?>
    <?php if (have_posts() ) : ?>
    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    nice one. awesome thanks.

    Thread Starter kvnmcwebn

    (@kvnmcwebn)

    That works really well with my existing archive page. thanks again. very nice bit of code there.

    If your problem has been solved, please use the dropdown on the right to mark this topic ‘Resolved’ so that anyone else with this question can see that there is a solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to limit posts displayed with this codeblock by category’ is closed to new replies.