Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //modify the main query for category pages
- function td_modify_main_query_for_category_page($query) {
- //checking for category page and main query
- if(!is_admin() and is_category() and $query->is_main_query() ) {
- //get the number of page where on
- $paged = get_query_var('paged');
- //get the limit of posts on the category page
- $limit = get_option('posts_per_page');
- //offset is hardcoded because of big grid
- $offset = 5;
- // offset + custom pagination - if we have offset, wordpress overwrites the pagination and works with offset + limit
- if (!empty($offset) and $paged > 1) {
- $query->set('offset', $offset + ( ($paged - 1) * $limit) );
- } else {
- $query->set('offset', $offset);
- }
- //print_r($query);
- }//end if main query
- }
- add_action('pre_get_posts', 'td_modify_main_query_for_category_page');
Advertisement
Add Comment
Please, Sign In to add comment