1
  • 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')); ?>" 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

  • Share some code with us. Other wise it is pretty tough to figure out your actual problem. – CodeMascot Feb 16 '17 at 14:37
  • @the_dramatist I've updated my question. There's nothing more. It worked before I modify Permalink structure from /%category%/%postname%/ to /blog/%category%/%postname%/ – Fabien Charrasse Feb 16 '17 at 16:24
2

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' 
    );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.