function wpsites_exclude_latest_post $query if $query-is_home && $query-is_main_query $query-set offset 5 ; add_action pre_get_posts wpsites_exclude_latest_post 5 ;修复第二页错误
要修复第二页错误,可以尝试将上述代码中的 'offset' 值改为当前页面数乘以每页显示的文章数,即:
function wpsites_exclude_latest_post( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; $query->set( 'offset', 5 + ( $paged - 1 ) * get_option( 'posts_per_page' ) ); } } add_action( 'pre_get_posts', 'wpsites_exclude_latest_post', 5 );
这样,第一页的文章不会被排除,从第二页开始才会排除最新的一篇文章。
原文地址: https://www.cveoy.top/t/topic/heqd 著作权归作者所有。请勿转载和采集!