我创建了一个仅在主页上显示最新5个帖子的功能。但它也显示在第2页。
我的代码是:
function wp_latest_pst()
{
$the_query = new WP_Query( array
(
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page' => 5
) );
if ( $the_query->have_posts() ) :
$p_count=$the_query->post_count;
switch ($p_count)
{
case '1':
$content = '<div class="featured-1 featured clearfix">';
break;
case '2':
$content = '<div class="featured-2 featured clearfix">';
break;
case '3':
$content = '<div class="featured-3 featured clearfix">';
break;
case '4':
$content = '<div class="featured-4 featured clearfix">';
break;
case '5':
$content = '<div class="featured-5 featured clearfix">';
break;
}
echo $content;
while ( $the_query->have_posts() ) : $the_query->the_post();
get_template_part( 'template-parts/featured', get_post_format() );
endwhile;
?>
</div>
<?php
endif;
wp_reset_postdata();
}
我在index.php上使用此函数:
<?php
if ( is_home() || is_front_page() ):
wp_latest_pst();
endif;
?>
我不想在下一页上使用CSS来隐藏它。 有什么建议吗?