我很难实现一个PHP计数器来将我的列表元素包裹在无序列表标记中。在while循环内部实现一个PHP计数器来包装带有ul元素的列表项目
我想环绕每3个列表元素。
我一直在尝试使用这些以前的问题作为指导,但没有多大用处。
easier way to get counter from while loop?
php loop counter bootstrap row
<?php
$counter = 0;
echo '<ul class="products latestCourses">';
while (have_posts()) : the_post(); ?>
<?php wc_get_template_part('content', 'product'); ?>
<?php $counter = $counter++; ?>
<?php if ($counter%3 == 0) echo '</ul><ul class="products latestCourses">'; ?>
<?php endwhile; // end of the loop. ?>
这是我迄今为止页面模板只包含一个列表元素。
当前此代码正在将每个列表项目包装在一个无序列表中。
..或者'$计数器+ = 1;' – simon
完善。谢谢! –