Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

got myself in a bit of a pickle. I want to display posts on category.php from the categories 'latest news' and 'custom models' only. The other category, 'press releases' is shown in a separate column.

I've the following code - hashed together from misc articles I've read - but it's showing ALL the posts rather than just my 2 chosen categories.

Perhaps the easiest way would be to show all posts apart from 'press releases'...

Can anyone help?

  <div id="rightColumn">
    <h1>
      <?php single_cat_title() ?>
    </h1>
    <?php $posts = get_posts('category=Latest News,Custom Models'); foreach($posts as $post) { ?>
    <div class="newsListing">
      <div class="imageContainer"><a href="<?php the_permalink(); ?>">
        <?php
// Must be inside a loop.

if ( has_post_thumbnail() ) {
    the_post_thumbnail('size-2');
}
else {
    echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/shared/placeholder.jpg" />';
}
?>
        </a></div>
      <h2><a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        </a></h2>
      <h3>
        <?php the_time('F jS, Y') ?>
      </h3>
      <?php the_excerpt(); ?>
      <p class="readMore"><a href="<?php the_permalink(); ?>">Read more</a></p>
      <div class="clearBoth"></div>
    </div>
    <?php } ?>
    <div class="clearBoth"></div>
    <div id="nav-below" class="navigation">
      <p class="floatRight">
        <?php posts_nav_link('','&lt; Recent entries','Older entries &gt;'); ?>
      </p>
      <div class="clearBoth"></div>
    </div>
  </div>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Function get_posts accepts comma separated categories' ids or slugs, not names. As it makes use of WP_Query, see Category Parameters.

share|improve this answer
    
So code will change to this... <?php $posts = get_posts('category_name=latest-news,custom-models'); foreach($posts as $post) { ?> –  V Neal Dec 14 '12 at 10:40
    
Yes, that's right. –  Max Yudin Dec 14 '12 at 10:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.