【发布时间】:2020-10-14 23:56:08
【问题描述】:
我有这个循环显示来自 WordPress 博客的帖子数据 -
<?php foreach ( $product_posts as $post ) : setup_postdata( $post ); ?>
<div class="card-container">
<div class="card-image">
<figure>
<a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?></a>
</figure>
</div>
<div class="gallery-card-text">
<h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
<p><?php the_excerpt() ?></p>
</div>
</div>
<?php endforeach; wp_reset_postdata(); ?>
使用这个 jQuery 函数 -
$(".card-container").mouseenter(function () {
$(".gallery-card-text").show();
$(".card-image").hide();
});
它针对循环中的所有内容,因此如果您将鼠标悬停在 1 个帖子上,它会隐藏所有帖子上的图像。我想在鼠标输入时单独显示/隐藏循环中的每个 div。
我该怎么做?
【问题讨论】:
-
为什么还要使用 JavaScript?
标签: php jquery wordpress loops