Guest User

Untitled

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