I’m really stuck on what to search for to get a start on this.
I want to be able to output 2 posts in one loop, so I can DIV wrapping 2 posts at one time…
What I’ve done below is just pure example – i’m trying to explain what I need it to do.
If any knows a way or where I can find a tutorial, that would be awesome! Thanks.
THE LOOP
Thanks to @Rob for helping me get this far, but it seems to output duplicates weirdly…
<?php $latest = new WP_Query(array(
'category_name' => 'news',
'order' => 'DESC',
'orderby' => 'date',
'posts_per_page' => 6
)); ?>
<?php $i = 0; if ( $latest->have_posts()) : while ($latest->have_posts()) : $latest->the_post(); ?>
<?php $odd = ++$i % 2; ?>
<?php if($odd) : ?>
<div class="dual-post-wrapper">
<?php endif; ?>
<div class="post-<?php the_ID(); ?>">
<?php the_content(); ?>
</div>
<?php if(!$odd) : ?>
</div>
<?php endif; ?>
<?php endwhile; unset($latest); endif; ?>
THE OUT PUTTED HTML
This is what the outputted HTML is looking like – for some reason it is duplicating post 1,2,3 and 4??? Weird!
<div class="dual-post-wrapper">
<div class="post-1">
Post 1 Content
</div>
<div class="post-2">
Post 2 Content
</div>
</div>
<div class="dual-post-wrapper">
<div class="post-3">
Post 3 Content
</div>
<div class="post-4">
Post 4 Content
</div>
</div>
<div class="dual-post-wrapper">
<div class="post-5">
Post 5 Content
</div>
<div class="post-6">
Post 6 Content
</div>
</div>
<div class="dual-post-wrapper"> <!-- these are duplicates?? -->
<div class="post-1">
Post 1 Content
</div>
<div class="post-2">
Post 2 Content
</div>
</div>
<div class="dual-post-wrapper"> <!-- these are duplicates?? -->
<div class="post-3">
Post 3 Content
</div>
<div class="post-4">
Post 4 Content
</div>
</div>
Thanks again!!
You can accomplish this with a simple counter and modulus.
That should work if you always have an even number of posts. You should probably count the number of posts before hand and close the div
if(!$odd || $last)