简体   繁体   中英

Wordpress the loop contain every 2 posts within a div

I have this code below. What I'm trying to do is contain each pair of 2 posts in between the <div class"ef-slide"> How would I do that?

<div class="ef-slide">

<?php 

$recent_blog_posts = new WP_Query('posts_per_page=6');

if ($recent_blog_posts->have_posts()) :

  while ($recent_blog_posts->have_posts()) : $recent_blog_posts->the_post();

       get_template_part( 'content' );  

  endwhile;

  else :
       echo "No Posts";

endif;

?>

This should do it:

<?php 

  $recent_blog_posts = new WP_Query('posts_per_page=6');

  if ($recent_blog_posts->have_posts()) :

    while ($recent_blog_posts->have_posts()) : $recent_blog_posts->the_post();
        ?>
        <div class="ef-slide">
        <?php
            get_template_part( 'content' );  

            $recent_blog_posts->the_post();
            if ($recent_blog_posts->have_posts())
               get_template_part( 'content' );  
         ?>
        </div>
        <?php

    endwhile;

    else :
         echo "No Posts";

  endif;

  ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM