Pagination on taxonomy archive pages breaks

I’ve created archive pages for all my taxonomies (taxonomie-{taxonomy-name}.php) and this works fine. The slug of my taxonomies are the same as the slug of it’s post-type. This makes it possible to create neat hierarchy in the URL, for example:

When post-type products has ‘type’ as a taxonomy with the values book, cd and dvd. post-type1 has the slug product and taxonomy1 has the same slug: product.

Read More

This way I can list the taxonomy-archives in the following way:

products/book

products/cd

products/dvd

and this works great. However: the pagination works on the products archives but on the products/{type} archive it gives a 404.

Any clue?

Code of the taxonomy template is as follows:

  <?php get_header(); ?>
  <section id="inhoud" class="hfeed">
    <nav class="navigatiebalk">
      <ul class="pagina-navigatie">
        <li class="volgende-pagina"><?php previous_posts_link(''); ?></li>
        <li class="vorige-pagina"><?php next_posts_link(''); ?></li>
      </ul>
    </nav>

    <?php while ( have_posts() ) : the_post(); ?>
    <?php
    $post_type = get_post_type( get_the_ID() );
    ?>
        <article class="hentry publicaties artikel <?php echo $post_type ?>">
            <header class="artikel-hoofd">
            <?php the_title( '<h1 class="titel"><span class="datum date">' . the_date('d.m.y', '', '', false) . '</span><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h1>' ); ?>
            <figure class="icoontje"></figure>
            </header>

            <section class="inleiding">
                <figure class="bericht-icoon"><?php $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '<a href="' . $large_image_url[0] . '" class="thumbnail-link colorbox" rel="lightbox" title="' . the_title_attribute('echo=0') . '" >'; the_post_thumbnail('thumbnail', array('class' => 'artikel-thumbnail')); ?></a>
                </figure>
                <span><?php $this_excerpt = get_the_excerpt(); echo $this_excerpt; ?>...&nbsp;<a href="<?php the_permalink(); ?>" class="lees-verder">Lees en luister</a>
                </span>
            </section>
        </article>
    <?php endwhile; ?>
    <nav class="navigatiebalk">
      <ul class="pagina-navigatie">
        <li class="volgende-pagina"><?php previous_posts_link(''); ?></li>
        <li class="vorige-pagina"><?php next_posts_link(''); ?></li>
      </ul>
    </nav>
  </section>
  <?php get_footer(); ?>

Related posts

Leave a Reply

2 comments

  1. Figured it out myself. Apparently, the pagination break because both my ‘products’ and my ‘types’ (those are not the terms I have, just for demonstration purposes) are having the same slug. Products has a slug of ‘products’ and types has a slug of ‘products/%typename%’. Due to this I can make my permalinks hierarchical: products/dvd or products/cd. It worked, although, it broke both my pagination on taxonomy archive-pages as it broke my permalinks to individual post-types. What I did was the following to fix it:

    function add_rewrite_rules($rules) {
        $newrules['([^/]+)/([^.]+).html$'] = 'index.php?$matches[1]=$matches[2]';
        $newrules['([^/]+)/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?post_type=$matches[1]&locations=$matches[2]&paged=$matches[3]';
    
        $rules = $newrules + $rules;
        return $rules;
    }
    
    add_filter('rewrite_rules_array', 'add_rewrite_rules');
    

    I added some mod-rewrite rules so apache will find the paginated taxonomy archive and the individual archive-post.