我正在显示数据库中的数据。当前,我的数据库中有6条记录,并且我得到的输出是
<ul>
<li>Records1</li>
<li>Records2</li>
<li>Records3</li>
<li>Records4</li>
<li>Records5</li>
<li>Records6</li>
</ul>
现在我正在做的是,我必须在第4个</ul>
标签之后关闭li
标签,然后在第4个ul
之后启动新的li
。
我的预期输出是
<ul>
<li>Records1</li>
<li>Records2</li>
<li>Records3</li>
<li>Records4</li>
</ul>
<ul>
<li>Records5</li>
<li>Records6</li>
</ul>
可能吗?
我正在使用下面的代码
<?php
if ($tyler_query->have_posts()) {
$index = 0;
$check=0;
$first4=0;
while ( $tyler_query->have_posts() ) {
$tyler_query->the_post();
if ($index < 4) {
if ($first4==0){?>
<ul>
<?php $first4=1;}?>
<li>
<!--output here-->
</li>
<?php if ($first4==4){?>
</ul>
<?php }?>
<?php }
else {
if ($check==0){?>
<ul>
<?php $check=1;}?>
<li>
<!--output here-->
</li>
<?php } $index++;}?>
</ul>
<?php }?>
如果您回显要在浏览器中看到的HTML标记/输出,您的代码将起作用。