ワードプレスで、記事スライダーを作っているのですが、スライダーで中央にきたときだけ、サムネイル画像の上にタイトルを表示させたいです。
記事が中央にくるとき、"active"のクラスが追加されるので、"active"でif文を書き、表示するかしないかの条件分岐をしたいのですが、phpでクラス名での条件式はどのように書けばいいか教えてください。
<div class="swiper-wrapper"> <!-- Slides --> <?php $rows = array( 'posts_per_page' => 4, ); $sliderPosts = get_posts($rows); if($sliderPosts && is_sticky()) : foreach($sliderPosts as $post) : setup_postdata( $post ); ?> <div class="swiper-slide"> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <a href="<?=get_the_permalink()?>"> <?php the_post_thumbnail('slider', array('class' => 'slider-img')); ?> <?php if() : ?> <div class="slider-text"> <h4 class="card-text category-tx"><?php echo $cat_name; ?></h4> <h3 class="title-tx"><?php echo mb_strimwidth(get_the_title(), 0, 100, "…", "UTF-8"); ?></h3> </div> <? endif; ?> </a> </div> </div> <?php endforeach; endif; wp_reset_postdata(); ?> </div>
回答1件
あなたの回答
tips
プレビュー