admin管理员组文章数量:1384141
I'm trying to offset the first 3 posts in the functions.php from a query but the next affects all my queries in the homepage:
add_action('pre_get_posts', 'myprefix_query_offset', 1 );
function myprefix_query_offset(&$the_query) {
//Before anything else, make sure this is the right query...
if ( ! $the_query->is_home() ) {
return;
}
//First, define your desired offset...
$offset = 3;
//Next, determine how many posts per page you want (we'll use WordPress's settings)
$ppp = get_option('posts_per_page');
//Next, detect and handle pagination...
if ( $the_query->is_paged ) {
//Manually determine page query offset (offset + current page (minus one) x posts per page)
$page_offset = $offset + ( ($the_query->query_vars['paged']-1) * $ppp );
//Apply adjust page offset
$the_query->set('offset', $page_offset );
}
else {
//This is the first page. Just use the offset...
$the_query->set('offset',$offset);
}
}
Is there any way to simply call one specific query?
Thank you.
本文标签: functionsSelecting specific query for offset
版权声明:本文标题:functions - Selecting specific query for offset 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744467833a2607619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论