这是我的代码,我想在第二个子循环中添加一个类。请告诉我我该怎么做。我是wordpress的新手。
<?php
$args = array(
'posts_per_page' => 3,
'post_type' => 'hosting_plan',
'order' => 'ASC'
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<div class="hostplbx /*here i want to add class on second child*/">
<h3><?php the_field('plan_name'); ?></h3>
<div class="hostprice">
<span class="hosprice"><b class="rs"><?php the_field('plan_price'); ?></b> per month</span>
<span class="plandetail"><?php the_field('tag_line'); ?></span>
</div>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
答案 0 :(得分:0)
您可以使用一个简单的迭代器变量 - 您可以更改一些示例代码以应用于您的模板:
$counter = 1;
if ( have_posts() ) : while ( have_posts() ) : the_post();
if($counter == 2) echo "<div class='second_child_class'>content goes here</div>";
else echo "<div>content goes here</div>";
$counter++;
endwhile; endif;