Adding random comment excerpts to a random posts loop
-
I’m currently calling the following to render random thumbnail posts on my index page and category pages
<?php query_posts(array('orderby' => 'rand', 'category_name' => 'All', 'showposts' => 4)); if (have_posts()) : while (have_posts()) : the_post(); ?> <?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { // the current post lacks a thumbnail echo 'no thumbnail dufus!'; } ?> <?php endwhile; else: ?> ... <?php endif; ?>
I also want to add another loop in these templates to generate 3 or 4 random comment excerpts. I’ve tried all sorts of things but can’t seem to work out how to generate only a few random comment excerpts and by category as I am not familiar with all of the wordpress gubbins around commenting.
I was thinking that the simplest would be to add another post loop underneath the main post loop on the page so that it would pick comments from random posts first, by a category name called ‘All’, then show one comment per each of those 4 random posts. I don’t want them to be the same random posts that are in the first post loop.
<?php query_posts(array('orderby' => 'rand', 'category_name' => 'All', 'showposts' => 3)); if (have_posts()) : while (have_posts()) : the_post(); ?> //a 'foreach' command goes here for a comment array????? <?php comment_excerpt(); ?> //end a foreach????? <?php endwhile; else: ?> ... <?php endif; ?>
Will this work?
If so, can someone tell me what i need to add around <?php comment_excerpt(); ?> to make sure it only shows one comment per post and what i need to envelope around <?php comment_excerpt(); ?> to get it to show in the first place?
I will send curlywurlys or any other quaint english chocolate to anyone who can help me.
- The topic ‘Adding random comment excerpts to a random posts loop’ is closed to new replies.