• Hey guys,

    I’ve been looking at this problem for a few weeks now, constantly running into the same problem. It’s a bit of a complicated setup:

    I’ve got a category called “dossiers”. I have also got a custom taxonomy “dossiers” which is used to group posts that are about the same news event or story.
    When someone creates a post, they can assign the post to certain dossier and then put it in the category for “dossiers”. That way, all dossier-posts are filed under the same category while still having a way to separate stories from each other.

    I need the category page for the category “dossiers” to display all the custom taxonomy terms in the taxonomy “dossiers”. These, in turn, link to their own listing of that particular dossier. I created the category-dossiers.php file which replaces the default category page, so that’s not a problem anymore.

    Using other forum posts, particular this one, I have gotten the bulk of the problem figured out. The category-page shows all taxonomy terms, with links and everything, and can split them up into pages. (This is a bit hacky because WordPress normally doesn’t use terms as the main content blocks, but posts).

    My only problem right now is to get the second, third, etc. page working. Beyond the first page it just displays the default index.php file of my theme.

    Here is the full template page. Can anyone figure out what’s wrong with it? I’ve tried and tried but just can’t seem to find the problem.

    <?php get_header(); ?>
    
    <?php get_sidebar (); ?>
    
    	<section class="articles grid main-content category">
    		<header class="grid-header">
    				<h2><?php single_cat_title();?></h2>
    		</header>
    			<?php
    
    				if ( get_query_var( 'paged' ) ) {
    					$paged = get_query_var('paged');
    					}
    				else if ( get_query_var( 'page' ) ) {
    					$paged = get_query_var( 'page' );
    					}
    				else {
    					$paged = 1;
    					}
    
    				$per_page    = 20;
    				$number_of_terms = count( get_terms( "dossiers") );
    				$offset      = $per_page * ( $paged - 1) ;
    
    				// Setup the arguments to pass in
    				$args = array(
    					'order'		=> 'ASC',
    					'orderby'      => 'menu_order',
    					'offset'	=> $offset,
    					'number'	=> $per_page
    				);
    
    				// Gather the terms
    				$terms = get_terms("dossiers", $args);
    
    				$count = count($terms);
    				if ( $count > 0 ){
    					echo "<ul>";
    					foreach ( $terms as $term ) {?>
    						<li class="article">
    							<a href="<?php echo get_term_link( $term ); ?>">
    								<?
    									if ( get_field('banner', $term->taxonomy._.$term->term_id) ) { // check if the post has a Banner Image assigned to it.
    										$image = get_field('banner', $term->taxonomy._.$term->term_id);
    										echo '<img class="wp-post-image" src="'.$image[sizes]['thumbnail'].'" />';
    									}
    									else {
    										echo '<img class="wp-post-image" src="' . get_bloginfo( 'stylesheet_directory' ) . '/img/missing-thumbnail.png" />';
    									}
    								?>
    								<div class="meta-info" />
    									<div class="caption" data-category="<?php $category = get_the_category(); echo $category[0]->slug; ?>"><?php echo $term->name; ?> </div>
    								</div>
    							</a>
    						</li>
    				     <?}
    				     echo "</ul>";
    				 }
    			?>
    	</section>
    
    	<nav class="pagination">
    
    		<?php 
    
    				if($terms) {
    
    						$big = 999999999; // need an unlikely integer
    						echo paginate_links( array(
    							'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    							'format'  => '/page/%#%',
    							'current' => $paged,
    							'total'   => ceil( $number_of_terms / $per_page ), // 3 items per page
    							'type' => 'list',
    							'mid_size' => 5
    						) );
    
    				}
    ?>
    		</nav>
    
    <?php get_footer(); ?>
  • The topic ‘/page/2 (pagination) while listing taxonomy terms (and not on a taxonomy page)’ is closed to new replies.