Guest User

Untitled

a guest
Apr 28th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. add_action('pre_get_posts', 'td_modify_main_query_for_blog_page');
  2. function td_modify_main_query_for_blog_page($query) {
  3.  
  4. //checking for blog page and main query
  5. if(!is_admin() and $query->is_main_query() and (is_front_page() and is_home() )) {
  6.  
  7. //get the number of page where on
  8. $paged = get_query_var('paged');
  9. //get the limit of posts on the page
  10. $limit = get_option('posts_per_page');
  11. //offset is hardcoded because of big grid
  12. $offset = 5;
  13.  
  14. // offset + custom pagination - if we have offset, wordpress overwrites the pagination and works with offset + limit
  15. if(empty($query->is_feed)) {
  16. if ( ! empty( $offset ) and $paged > 1 ) {
  17. $query->set( 'offset', $offset + ( ( $paged - 1 ) * $limit ) );
  18. } else {
  19. $query->set( 'offset', $offset );
  20. }
  21. }
  22.  
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment