Splitting up the output of get_posts
-
I’m trying to split up the output of get_posts in seperate divs per 2 posts. I.E:
<div container> <div sub> post 1 post 2 </div><!--- sub ---> <div sub> post 1 post 2 </div><!--- sub ---> </div><!--- container --->
Im trying to accomplish this with array_chunk() and a double foreach.
$allposts = get_posts('numberposts=6'); $postgroup = array_chunk($allposts, 2); echo '<div class="container">'; foreach ($postgroup as $posts) { echo '<div class="sub">'; foreach ($posts as $post) { echo '<li>'; php the_title(); echo '</li>'; } echo '</div>'; } echo '</div>'; }
This works in so far I do get 6 posts and the divs are in the correct place… but… it’s 6 times the same post.
Where does my thinking go wrong here?
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Splitting up the output of get_posts’ is closed to new replies.