简体   繁体   English

WordPress查询循环div显示

[英]WordPress query loop div display

Hello I want to display posts like this. 您好我想显示这样的帖子。

<div class="item">
  <div class="row">
    Post No 1.
    Post No 2.
  </div>
  <div class=row 2>
    Post No 3.
    Post No 4.
    Post No 5.
  <div>
</div>

Here is code what i am trying. 这是我正在尝试的代码。

 <?php 
                    global $paged, $wp_query, $wp;
                    $arags = array(
                        'post_type' => 'post',
                        'posts_per_page' => 5,
                    );
                    $count = 1;
                    $itemClass = '';
                    $wp_query = new WP_Query($arags);
                    while ($wp_query->have_posts()) : $wp_query->the_post();
                    ?>
                    <?php 
                    if($count == 1) :
                        echo '<div class="item">';
                        echo '<div class="row">';
                    endif;

                    if($count == 1 || $count == 2) :
                        get_template_part( 'templates/mag/mag-loop-big' );
                    endif;


                    if($count == 1) :
                        echo '</div>';
                        echo '</div>';
                    endif;
                    ?>
                    <?php $count++; ?>                      
                    <?php endwhile; ?>
                    <?php wp_reset_postdata(); ?>
                    <?php wp_reset_query(); ?>

This Code display first post in Item and Div class. 此代码显示Item和Div类的第一篇文章。 But second div shown out side of row and item div. 但是第二个div显示在行和项目div的外侧。 Here is current result. 这是当前结果。

<div class="item">
<div class="row">
    Post No 1.
 </div>
</div>
 Post No 2.
 Post No 3.
Post No 4.

Any solution for this?? 任何解决方案? Thanks in advance. 提前致谢。

your conditions are not the right one for that result try this 您的条件不适合该结果,请尝试此

if($count == 1) :
echo '<div class="item">';
echo '<div class="row">';
if($count == 1) :
get_template_part( 'templates/mag/mag-loop-big' );
endif;
if($count == 2) :
echo '</div>';
endif;
 if($count == 3) :
 echo '<div class="row2">';
 if($count == 5) :
 echo '</div>';
 echo '</div>';
 endif;
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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