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