Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress查询循环div显示_Php_Wordpress_While Loop - Fatal编程技术网

Php WordPress查询循环div显示

Php WordPress查询循环div显示,php,wordpress,while-loop,Php,Wordpress,While Loop,你好,我想显示这样的帖子 <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> 一号邮政。 2号邮递员。 第三站。 第四站。 第五站。 下面是我正在尝试的代码

你好,我想显示这样的帖子

<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>

一号邮政。
2号邮递员。
第三站。
第四站。
第五站。
下面是我正在尝试的代码

 <?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(); ?>

此代码显示项目和Div类中的第一个post。 但第二个div显示在行和项div的外侧。 这是目前的结果

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

一号邮政。
2号邮递员。
第三站。
第四站。
有什么解决办法吗??
提前感谢。

您的条件不适合该结果,请尝试此方法

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;
?>
如果($count==1):
回声';
回声';
如果($count==1):
获取模板零件('templates/mag/mag loop big');
endif;
如果($count==2):
回声';
endif;
如果($count==3):
回声';
如果($count==5):
回声';
回声';
endif;
?>

显示代码的结果,因为您在第一次发布后关闭了div
if($count==1):echo“”;回声';endif结果添加问题已更新。