Html 将CSS代码添加到loop-WordPress的每三次迭代中
我想为这个WP循环的每三次迭代添加一个Html 将CSS代码添加到loop-WordPress的每三次迭代中,html,css,wordpress,loops,while-loop,Html,Css,Wordpress,Loops,While Loop,我想为这个WP循环的每三次迭代添加一个style=“background:green” 我如何做到这一点 if( have_posts() ) : while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <li>Test</li> <?php endwhile; ?> <?php endif; if(have_posts())
style=“background:green”
我如何做到这一点
if( have_posts() ) :
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<li>Test</li>
<?php endwhile; ?>
<?php endif;
if(have_posts()):
而($wp_query->have_posts()):$wp_query->the_post();
?>
试验
您是否尝试过使用%运算符。类似以下内容(未经测试):
if(have_posts()):
$i=0;
而($wp_query->have_posts()):$wp_query->the_post();
$i++;
?>
您是否尝试过使用%运算符。类似以下内容(未经测试):
if(have_posts()):
$i=0;
而($wp_query->have_posts()):$wp_query->the_post();
$i++;
?>
也许是一个递增的变量和模运算符的用法,只是一个想法,类似于WP:可能是一个递增变量和模运算符的用法,只是一个想法,类似于WP:
if( have_posts() ) :
$i=0;
while ($wp_query->have_posts()) : $wp_query->the_post();
$i++;
?>
<li <?php if(($i % 3)==0)echo 'style="background:green"';?>>Test</li>
<?php endwhile; ?>
<?php endif;