我必须在php ot thuis的foreach循环中的第一个、第三个和第五个元素中添加一个特定的类,代码如下=〉
<?php foreach($leaders as $l) : ?>
<?php if(get_field('type', $l->ID) == 'NY Staff') : ?>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="member-info">
<div class="photo">
<img class="img-responsive" src="<?php the_field('image', $l->ID); ?>" alt="">
</div>
<div class="info">
<div class="name"><?php echo get_the_title($l->ID); ?></div>
<div class="body">
<div><span class="job-name"><?php the_field('position', $l->ID); ?>,</span> based in <?php the_field('location', $l->ID); ?></div>
<a href="<?php echo get_permalink($l->ID); ?>" class="read-more">
<svg id="_24x24" data-name="24x24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><defs><style>.cls-1{fill:#FFFFFF;}</style></defs><path id="icon-arrow-right" class="cls-1" d="M12.46 12L6 19l2.77 3L18 12 8.77 2 6 5l6.46 7z"/></svg>
</a>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
所以我必须将div=〉photo下面img元素中的这个类添加到下面的代码中
<div class="photo">
<img class="img-responsive" src="<?php the_field('image', $l->ID); ?>" alt="">
</div>
先谢谢你!干杯
1条答案
按热度按时间zaq34kh61#
根据需要,您可能会使用
nth-child
css选择器而避免添加类。例如:
或者
https://css-tricks.com/almanac/selectors/n/nth-child/
如果采用这种方法,您可能希望向父div添加一个类以使其更加明确。
一个二个一个一个