• I’m currently working on a website using a main content section as well as separate “featured” columns. I have a handful of categories created, and within the columns I’d like to only display posts from certain categories (for example, I have a “Coach’s Column” and in that column, I would only like to display posts categorized as so). I’ve found a way to exclude posts, but is there a way to only include certain post categories?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter mtx212s

    (@mtx212s)

    Got it working. Now I need to limit the post amount displayed, but I can’t get it to work properly with the ‘showposts=3’ tag.

    the syntax has changed to posts_per_page=3

    don’t know if that will change your results though

    you can post the code from your query and loop if you like

    use a pastebin if its long

    Thread Starter mtx212s

    (@mtx212s)

    <?php $temp_query = $wp_query; ?>
    <?php query_posts('cat=6,7,8,9,10,11,12'); ?>
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
              <?php the_date('','<h2>','</h2>'); ?>
    
              <div>
                 <h4 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h4>
                 <div class="meta"></div>
    
                 <div class="storycontent">
                     <?php the_content(__('(more...)')); ?>
                 </div>
    
                 <div class="feedback">
                     <?php wp_link_pages(); ?>
                     <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
                 </div>
    
              </div>
    
              <?php comments_template(); // Get wp-comments.php template ?>
    
              <?php endwhile; else: ?>
                 <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
              <?php endif; ?>
    
              <?php posts_nav_link(' — ', __('&laquo; Newer Posts'), __('Older Posts &raquo;')); ?>
    
              <?php wp_footer(); ?>
    
            </div>
    
            </div>
    Moderator keesiemeijer

    (@keesiemeijer)

    try it with:
    <?php query_posts('cat=6,7,8,9,10,11,12&posts_per_page=3'); ?>

    Thread Starter mtx212s

    (@mtx212s)

    Ahh the & is what did it. I kept getting a syntax error before. Thank you guys!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Only displaying posts from certain categories’ is closed to new replies.