admin管理员组文章数量:1323530
I have a permanent sticky post on my front page and have implemented the code (pasted below) into my functions.php file to stop it adding an extra post to my post count on the front page (it's a grid so i can't have one post dangling off the bottom).
However.... when the code is implemented it's adding a whopping 72 extra pages to my page count. From 799 (which is what it should be) to 871. Any page past 799 obviously comes up at 404 because it doesn't exist.
Can someone please help me figure out what's causing it? Cheers
add_action( 'pre_get_posts', function( $query )
{
if ( $query->is_home && $query->is_main_query() )
{
$posts_per_page = get_option( 'posts_per_page' );
$sticky_posts = get_option( 'sticky_posts' );
// if we have any sticky posts and we are at the first page
if ( is_array($sticky_posts) && !$query->is_paged() )
{
$sticky_count = count($sticky_posts);
if ( $sticky_count < $posts_per_page )
{
$query->set('posts_per_page', $posts_per_page - $sticky_count);
}
else
{
$query->set('posts_per_page', 1);
}
}
}
});
本文标签: functionsWordpress Sticky Post Count quotFixquot Breaking Pagecount by 72 pages
版权声明:本文标题:functions - Wordpress Sticky Post Count "Fix" Breaking Pagecount by 72 pages! 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742131049a2422160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论