404 on category.php pagination

  • My blog post page : mysite.com/blog => Work
    • Blog page pagination : mysite.com/blog/page/2 =>
      Work
    • A category post url : mysite.com/blog/cat => Work
    • A post url : mysite.com/blog/cat/postname => Work
    • A category post pagination url : mysite.com/blog/cat/page/2 =>
      404 ๐Ÿ™
    • Permalink structure : /blog/%category%/%postname%/
    • Remove category base with Yoast: ok

Category.php :

<?php get_header(); ?>
<?php get_sidebar('page'); ?>
<div class="posts-list">
    <ul class="categs-list">
        <li class="<?php if(is_home()):?>current-cat<?php endif;?>"><a href="<?php echo get_permalink(get_option('page_for_posts')); ?>" rel="nofollow noreferrer noopener" title="<?php _e('Voir tous les articles', 'fc'); ?>"><?php _e('Tous', 'fc'); ?></a></li>
        <?php wp_list_categories('title_li='); ?>
    </ul>
    <?php pagination(); ?>
    <?php 
    while ( have_posts() ) : the_post();
        $category = get_the_category();
        get_template_part( 'content-category', $category[0]->slug );
    endwhile;
    ?>
    <?php pagination(); ?>
</div>

<?php get_footer(); ?>

Function pagination() :

function pagination()
{

    if ( function_exists('wp_pagenavi') )
    {
        echo "<nav class='pagination'>";
            wp_pagenavi();
        echo "</nav>";
    }

}

Why do i get 404 with pagination ?

Edit: mysite.com/blog/cat/feed doesnโ€™t work either

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & Iโ€™ll get back to you as soon as possible.

Method 1

Thanks to this and this i was able to adapt the solution to my problem.

Solution:

add_action( 'init', 'wpa58471_category_base' );
function wpa58471_category_base() {
    add_rewrite_rule(
        'blog/([^/]+)/page/(d+)/?$',
        'index.php?category_name=$matches[1]&paged=$matches[2]',
        'top' 
    );
    add_rewrite_rule( 
        'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$',
        'index.php?category_name=$matches[1]&feed=$matches[2]', 
        'top' 
    );
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x