How to modify loop to split posts into groups of threes?
-
I am attempting to build a ‘Featured Posts’ slideshow at the top of my blog home page. I am using jquery scrollable to display the featured posts, and I have this part working. My problem is that scrollable requires the items (posts), to be displayed in groups separated within divs. I am not sure how to structure the loop, to do this.
This is the format I need WordPress to display the posts from my ‘Featured’ category:
<!-- 1-3 --> <div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> </div> <!-- 4-6 --> <div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> </div> <!-- 7-9 --> <div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> <div class="single_item"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div> </div>
As you can see, I need to request posts three at a time, incapsulated within a div.
I imagine this is very simple with some basic php, I just have not been able to figure out how to do it myself.
Thanks for any assistance you may be able to offer!
- The topic ‘How to modify loop to split posts into groups of threes?’ is closed to new replies.