【发布时间】:2018-01-31 04:05:31
【问题描述】:
我想连续每第二个项目添加一个类,请帮助, 提前致谢
添加一些虚拟内容以满足其标准
<?php $counter = 1 ?>
<div class="services-posts mt2 pull-right">
<?php
$args = array( 'post_type' => 'services');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $featured_img_url = get_the_post_thumbnail_url('full'); ?>
<div class="col-sm-4 <?php if ($counter % 2 == 0) : ?> animation-fadeInUp <?php endif; ?> <?php if ($counter % 1 == 0) : ?> animation-fadeInLeft <?php endif; ?> <?php if ($counter % 3 == 0) : ?> animation-fadeInRight <?php endif; ?> " >
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
/*I need to add a class to the each second box-div2 div */
<div style="background-image: url('<?php echo $image[0]; ?>')" class="box-div2">
<?php endif; ?>
<div class="c-div">
<a href="">
<h4><?php the_title(); ?></h4>
<span>
<?php the_content(); ?>
</span>
</a>
</div>
</div>
</div>
<?php if ($counter % 3 == 0){echo '</div><div class="services-posts mt2 pull-right">';} ?>
<?php $counter++ ; ?>
<?php endwhile; ?>
【问题讨论】:
-
回答了类似的问题here
-
那是使用jquery的解决方案,我的是php
-
运行代码时当前发生了什么?
-
我需要在这个类的每一秒元素上创建一个类