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;
?>
显示代码的结果,因为您在第一次发布后关闭了divif($count==1):echo“”;回声';endif代码>结果添加问题已更新。