First thing:
Category archives default to using this permalink/URL structure:
http://example.com/category/<category slug>/ (for page #1)
http://example.com/category/<category slug>/page/<page number>/ (for page #2, #3, and so on)
So when you visit http://example.com/category/accessories/page/2/
, WordPress will automatically make a call to WP_Query
and the parameters being used are retrieved from the current page URL:
WP_Query( array(
'category_name' => 'accessories', // the <category slug> in the URL
'paged' => 2, // the <page number> in the URL
) );
And that is the main query.
So when the paged
value is greater than the max number of pages for the main query, then a 404
error page would be displayed. And in your case, does the category accessories
actually have enough number of posts for the archive page to have a page #2? I bet no.
Second thing:
Category templates should just display posts retrieved via the main query:
while ( have_posts() ) {
the_post();
// Display the post.
}
But I’m not seeing that anywhere in your code.
Third thing:
You can use pre_get_posts
to alter the main query by modifying its parameters:
// This should go in your theme's functions.php file.
add_action( 'pre_get_posts', function ( $query ) {
// Set the number of posts per page to 6, but only on category archives.
if ( ! $query->is_admin && $query->is_main_query() && is_category() ) {
$query->set( 'posts_per_page', 6 );
}
} );
Then in your code, there’s no necessity for this:
$args = array('posts_per_page' => 6,'paged'=> $paged,);
$tyler_query = new WP_Query( $args ); // secondary query
Additionally:
-
Change the
$tyler_query->have_posts()
tohave_posts()
. -
Then change the
$tyler_query->the_post()
tothe_post()
. -
Just use
<?php next_posts_link(); ?>
without having to pass the max number of pages (the$tyler_query->max_num_pages
in your code).