【发布时间】:2017-05-15 14:32:55
【问题描述】:
我在我的网站上使用 php 循环。 我正在尝试将一个类“当前”随机添加到此循环内的 div 中。 我知道如何使用 jQuery 来做到这一点,但我想使用 php 来实现这一点。 这是我的循环:
<?php if (have_posts()) : ?>
<div id="random_backgrounds">
<?php while (have_posts()) : the_post(); ?>
<div id="background_directors" class="" background_ID="<?php the_ID();?>" style="background: url(<?php the_post_thumbnail_url( 'large' ); ?>) no-repeat center center fixed" ></div>
<?php endwhile; ?>
</div>
<?php endif; ?>
我想将“当前”类随机添加到“background_directors”div。
谁能帮我解决这个问题?
【问题讨论】:
-
首先:ID 在文档中必须是唯一的。
-
你是什么意思“随机添加一个类”?