php - Two posts in same div - WP loop -


i need following in wordpress:

<div class="posts-wrapped">     <div id="post-1" class="post">         <h1>title 1</h1>     </div>     <div id="post-2" class="post">         <h1>title 2</h1>     </div> </div> <div class="posts-wrapped">     <div id="post-3" class="post">         <h1>title 3</h1>     </div>     <div id="post-4" class="post">         <h1>title 4</h1>     </div> </div> 

i know how posts wp loop, how can wrap every 2 posts in .posts-wrapped div?

i fetch posts wp_query.

thanks!

edit: tried few ways it. example this:

$index=0; <div class="posts-wrapped">  <?php while ( have_posts() ) {     $index++;    ?> <div class="post">         <h1><?php the_post(); ?></h1>     </div> <?php if(($index % 2) ==0){ echo '</div><div class="posts-wrapped">'; } } ?>  </div> 

but prints 1 empty posts-wrapped div:

<div class="posts-wrapped">     lorem ipsum 1<br>     lorem 2 ipsum est<br> </div> <div class="posts-wrapped">     lorem ipsum 1<br>     lorem 2 ipsum est<br> </div> <div class="posts-wrapped"> </div> 

how can rid of last empty div? screws carousel (this content part of carousel).

get index counts loop iteration , check modulus operation know or odd

$index=0; <div class="posts-wrapped">  <?php while ( have_posts() ) {     $index++;    ?> <div class="post">         <h1><?php the_post(); ?></h1>     </div> <?php if(($index % 2) ==0){ echo '</div><div class="posts-wrapped">'; } } ?>  </div> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -