除了第一个博客页面之外,如何从博客页面隐藏滑块?

How can I hide slider from the blog pages except the first blog page?

如何使用 php 在我的 2,3,4... 博客页面中隐藏 Wordpress 中的顶部滑块?这是我的脚本:

<section id="blog">
       <div class="owl-carousel">
          <?php $loop = new WP_Query(array('post_type' => 'post', 'posts_per_page' => -1, 'orderby'=> 'ASC')); ?> 
          <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
             <div class="recent-post">
                <div class="home-slider-img">
                    <?php echo the_post_thumbnail(); ?>
                </div> 
                <div class="feat-overlay">
                    <div class="feat-overlay-inner"> 
                        <div class="post-header">                     
                            <span class="cat"><?php the_category(', ') ?></span>
                            <h4><a href="<?php the_permalink(); ?>"><?php print get_the_title(); ?></a></h4>
                            <span class="date"><?php the_time('M j, Y') ?></span>
                            <p><a class="read-more" href="<?php print get_permalink($post->ID) ?>">Read More</a></p>
                        </div>      
                    </div>  
                </div>
            </div>
          <?php endwhile; ?>
       </div>
    </section>

is_home() 函数应该做你想做的事 - https://developer.wordpress.org/reference/functions/is_home/

只需将您的 owl-carousel div 包装在 if 测试中,以检查您是否在博客主页上,如下所示:

<?php if (is_home()) { ?>
     <div class="owl-carousel">...</div>
<?php } ?>