I’m using a loop to generate the slides I need for a Coda Slider slideshow. The slides should be pulling the most recent post from 5 different categories. The problem I’m having is that it’s pulling the 5 most recent posts from the 5 categories collectively and not individually. So it’s pulling 2 posts from the 1st category and then 1 from each of the others.
Any way to get this to work properly?
This is the code I’m using:
<?php
$cat_post_query = new WP_Query($query_string . 'cat=7,8,10,9,11');
while ($cat_post_query->have_posts()) : $cat_post_query->the_post();
$do_not_duplicate = $post->ID;?>
<div>
* slide content *
</div>
<?php endwhile; ?>
For those who were interested in an answer to this question, I found the answer myself.
<div class="coda-slider" id="slideshow">
<?php
// array of category IDs
$categories = array(1,2,3,4,5);
foreach ($categories as $cat) :
$post = false;
$post = get_posts('cat=".$cat."&posts_per_page=1');
if($post) :
$post = $post[0];
setup_postdata($post); ?>
<!-- rest of normal loop -->
<div <?php post_class(); ?>>
<h2 class="title">title used to dynamically generate thumbs in codaslider</h2>
<h3><a href="https://wordpress.stackexchange.com/questions/71760/<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
The original foreach loop code came from this post:
http://wordpress.org/support/topic/display-most-recent-post-from-each-of-several-categories-on-home-page