pagination for blog landing page

This works for me with no 404s <?php $args = array ( ‘posts_per_page’ => 5 , ‘paged’ => $paged, ‘ignore_sticky_posts’ => true ); $blog_query = new WP_Query($args); if ( $blog_query->max_num_pages > 1 ) { next_posts_link(‘&larr; Older posts’, $blog_query->max_num_pages); previous_posts_link(‘Newer posts &rarr;’, $blog_query->max_num_pages); } while ( $blog_query->have_posts() ) { $blog_query->the_post(); // STUFF } if ( $blog_query->max_num_pages … Read more

One post on frontpage and an archive page

Alter the main query for the front/home page with is_front_page() and/or is_home(), like shown below: add_action(‘pre_get_posts’,’wpse104878_alter_main_query’); function wpse104878_alter_main_query($query){ if ( is_admin() || ! $query->is_main_query() ) { return; } if( $query->is_main_query() && is_front_page() || is_home() ){ $query->query_vars[‘posts_per_page’] = ‘1’; } } The archive page should work, if underscore starter theme has an template for it. You … Read more

WordPress: Getting “Newer Posts” and “Older Posts” links on a Specialized Page Template

You can achieve this using WP_Query as shown in the following code. To know more information on this visit this page. <?php $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; $the_query = new WP_Query( ‘posts_per_page=5&paged=’ . $paged ); if ( $the_query->have_posts() ) : // the loop while ( $the_query->have_posts() ) … Read more

Pagination for user list

You can use WP_User_Query class instead of get_users() function to achieve this. The new modified code will similar to following code. <?php /* * We start by doing a query to retrieve all users * We need a total user count so that we can calculate how many pages there are */ $count_args = array( … Read more

pagination custom post type on CP page

I’ve found the problem. Since I’m on a single (custom) post page, WP redirects back to the root of the URL. I’ve found the solution here. The solution (copied from the post on SO) was adding this to the functions.php: add_filter(‘redirect_canonical’,’pif_disable_redirect_canonical’); function pif_disable_redirect_canonical($redirect_url) { if( is_singular()) { $redirect_url = false; } return $redirect_url; } I’ve … Read more