Custom page-links for paginated posts | wp_link_pages quicktag

This is going to be kind of hackish, but it is possible using an alternate function. Add this to your theme’s functions.php file. function wp_link_pages_titled($args=””) { $defaults = array( ‘before’ => ‘<p>’ . __(‘Pages:’), ‘after’ => ‘</p>’, ‘link_before’ => ”, ‘link_after’ => ”, ‘echo’ => 1 ); $r = wp_parse_args( $args, $defaults ); extract( $r, … Read more

How to use pre_get_posts?

Remove all query code from the template and just leave the default loop. In your example code you’re overwriting the query in the template, in the code you pasted in the comments, you’re running an entirely new query. These are both unnecessary when using pre_get_posts. Put your pre_get_posts code in functions.php. You don’t have to … Read more

Paginate get related post by author function

As I already stated in a comment to your answer, you should never make use of query_posts Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of … Read more

How to create pagination on archive.php template

The solution was surprisingly simple as you can see below. Thanks for your help @Sally CJ and @Tom J Nowell. <?php get_header(); ?> <!– PAGE INTRODUCTION –> <div class=”container”> <h1 class=”page_title”><?php the_archive_title(); ?></h1> </div> <!– PAGE CONTENTS –> <div class=”container”> <div class=”row”> <!– POSTS –> <?php if ( have_posts() ) : while ( have_posts() ) … Read more

category/category_name pagination 404 error

In the template used for category archives you should have no use for new WP_Query. For all the main templates that WordPress loads itself for post archives, WordPress has already queried the correct posts, so you don’t need to query them again with WP_Query. For these templates, it’s the template’s job just to display those … Read more

wp_link_page – wrap current page element

I wouldn’t use WordPress’ internal function. We had a very similar question recently: How to style current page number (wp_link_pages)? I wrote a small but flexible function to replace wp_link_pages(). It is probably easier to extend this than hacking around the return value of the native function.

WordPress Pagination not displaying posts after certain page

WordPress determines if a paginated page exists based on the results of the main query. Each page is actually querying 6 posts, while your custom query only loads 3. The solution – Don’t create a new query in the template, use pre_get_posts to modify the main query via your theme’s functions.php function wpa90437_media_category( $query ) … Read more