Pagination bug with custom permalink structure

Hello

I have an issue with pagination not working, perhaps due to a custom permalink structure. The following link describes my issue and also suggests a fix…

How can I incorporate this fix into X theme?

1 Like

Hello There,

Thanks for writing in! Could you please share what is the custom permalink structure that you are using? To better assist you with this issue, please provide the url of your site and maybe an access to the WP so that can take a closer look.

Best Regards.

Hello

The permalink structure is:

/%category%/%postname%/

An example of the pagination that is failing can be seen here:

I believe that X Theme is trying to interpret “/page/” as a category which is producing a 404. The fix requires the addition of $paged to the query_posts function (as per the link in the initial request).

Thanks!

Hi There,

Please change the permalink settings to the post name instead:

Regards!

Hello

Unfortunately, that will change all of our URL’s and break our SEO.

Using query string pagination would fix this. Can we alter the child theme in some way?

Thanks
Jason

Hi Jason,

You can try this third party plugin.

Hope that helps.

Hello

Thanks for the suggestion, but that plugin was last updated six years ago! It’s designed for Wordpress version 2. Huge security risk there.

Can someone please answer whether it’s possible to implement query string based pagination using a child theme? Or whether core X Theme could be updated as a feature request?

Thanks
Jason

Hi Jason,

I will forward this as a feature request.

For the mean time, you can add the code below in your child theme’s functions.php file.


/* Fix Category Pagination */
function remove_page_from_query_string($query_string)
{ 
    if ($query_string['name'] == 'page' && isset($query_string['page'])) {
        unset($query_string['name']);      
        list($delim, $page_index) = split('/', $query_string['page']);
        $query_string['paged'] = $page_index;
    }      
    return $query_string;
}

add_filter('request', 'remove_page_from_query_string');


function fix_category_pagination($qs){
	if(isset($qs['category_name']) && isset($qs['paged'])){
		$qs['post_type'] = get_post_types($args = array(
			'public'   => true,
			'_builtin' => false
		));
		array_push($qs['post_type'],'post');
	}
	return $qs;
}
add_filter('request', 'fix_category_pagination');
/* End of Fix Category Pagination */

Hello

Thanks for the code snippet - the 404 error has gone, but when users click the pagination to see the next page, the URL changes but the user is shown the first page’s content.

Also, the pagination does not advance (shows “page 1” when the URL says “/page/2”).

Any ideas on how to fix?

Thanks

Hello There,

Using your permalink structure, I have tested it in my local testing server. With Ethos stack and in a category page, the pagination works. (https://prnt.sc/i8vtvy)

There must be something that is preventing the default pagination to work in your site. This could be caused by a 3rd party plugin. You could try testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

If the issue still exist, please re install X theme and Cornerstone. There might be some files that were corrupted. You can review our update guide and see the Manual Update section to re install X.

Please let us know how it goes.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.