php - WordPress offset posts on home page -


i offset homepage posts 5. have widget @ top shows first 5 already.

i use in functions.php offset. , works. problem widget doesn't print out posts beginning anymore. code below

add_action('pre_get_posts', 'myprefix_query_offset', 1);  function myprefix_query_offset(&$query) {      //before else, make sure right query...     if (!$query->is_home()) {         return;     }      //first, define desired offset...     $offset = 5;      //next, determine how many posts per page want (we'll use wordpress's settings)     $ppp = get_option('posts_per_page');      //next, detect , handle pagination...     if ($query->is_paged) {          //manually determine page query offset (offset + current page (minus one) x posts per page)         $page_offset = $offset + ( ($query->query_vars['paged'] - 1) * $ppp );          //apply adjust page offset         $query->set('offset', $page_offset);     } else {          //this first page. use offset...         $query->set('offset', $offset);     } } 

the widget uses this, , when does, hands first 5 of offset data set. , it's using get_featured_post variable.

$get_featured_posts = new wp_query(array(     'posts_per_page' => 5,     'post_type' => 'post',     'ignore_sticky_posts' => true         ) ); 

any appreciated.
thanks.

i think issue in code it's not applying right query.

 add_action('pre_get_posts', 'myprefix_query_offset', 1);  function myprefix_query_offset(&$query) {  //before else, make sure right query... if (!in_the_loop () || !is_main_query ()) {     return; }  //first, define desired offset... $offset = 5;  //next, determine how many posts per page want (we'll use wordpress's settings) $ppp = get_option('posts_per_page');  //next, detect , handle pagination... if ($query->is_paged) {      //manually determine page query offset (offset + current page (minus one) x posts per page)     $page_offset = $offset + ( ($query->query_vars['paged'] - 1) * $ppp );      //apply adjust page offset     $query->set('offset', $page_offset); } else {      //this first page. use offset...     $query->set('offset', $offset); } } 

can try code above , let me know if work.

thanks


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -