Pagination in WP_Query?

Put the following code in functions.php # +++++++++++++++++++++++++++++++Pagination ++++++++++++++++++++++++++++++++++++++ function kriesi_pagination($pages=””, $range = 2) { $prev = __(‘« Prev’); $next = __(‘Next »’); $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = 1; if($pages == ”) { global $wp_query; $pages = $wp_query->max_num_pages; if(!$pages) { $pages = 1; } } if(1 != $pages) { echo … Read more

Show more than one post on the main page excluding certain category

If you are altering main query then use pre_get_posts filter instead of WP_Query. add_action(‘pre_get_posts’,’wpse224610_alter_query’); function wpse224610_alter_query($query){ $cat_id = get_cat_ID(‘Featured articles’); $exclude_cat_id = -$cat_id; if( !is_admin() && $query->is_main_query() ){ $query->set( ‘cat’, $exclude_cat_id ); $query->set( ‘posts_per_page’, 4 ); } } And the main loop will be if( have_posts() ): while( have_posts() ): the_post(); //The loop endwhile; endif; … Read more

Rewrite rule pagination on different url levels

I have added extra rewrite rules for pages with no item_width and item_height in combination with pagination as follows: /** * Adds rewrite rules for shop category */ function gtp_add_shop_rewrite_rules() { // shop-category/category/item_width/item_height/page/2/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/([^/]*)\/([^/]*)\/page\/([0-9]*)$’, ‘index.php?shop-category=$matches[1]&item_width=$matches[2]&item_height=$matches[3]&paged=$matches[4]’, ‘top’ ); // shop-category/category/page/2/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/page\/([0-9]*)$’, ‘index.php?shop-category=$matches[1]&paged=$matches[2]’, ‘top’ ); // /shop-category/category/item_width/item_height/ add_rewrite_rule( ‘^shop-category\/([^/]*)\/([^/]*)\/([^/]*)$’, ‘index.php?shop-category=$matches[1]&item_width=$matches[2]&item_height=$matches[3]’, ‘top’ ); // /shop-category/category/item_width/ add_rewrite_rule( … Read more