• Resolved Pieter Bos

    (@senlin)


    Hi, seems that there is not an awful lot written about this subject yet, so I would like to try my luck here.

    On a website I have made a few custom taxonomies (hanging under Pages) and now I am trying to get the usual pagination to work.

    Coming from the page template is this line
    global $wp_query; $total_pages = $wp_query->max_num_pages; if ( $total_pages > 1 )
    but that doesn’t result in the desired effect; it just shows the first 10 pages within that taxonomy.

    Can anybody shed light on this for me please?

    Thanks so much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Pieter Bos

    (@senlin)

    OK, as I understand it, pagination is most probably not going to work?

    I would settle also for showing all instead of using pagination…

    It seems I have to do something with a wp_query, but I cannot figure out how to set this up to show all posts from a specific term on one taxonomy.

    For illustration:
    – I have 5 custom taxonomies (type, size, color, to name a few) hanging under Pages.
    – The taxonomy page “size” shows a short introduction about sizes and then lists all the terms within that taxonomy.
    – When a term is clicked in the above, you’ll get to the taxonomy-term page and after a short introduction I want to list all the Pages that use that same taxonomy term.

    I have accomplished all of this already with the exception of the “list all”-part: only the last 10 entries show up, nothing more.

    The code I have used is as follows:

    <h1 class="page-title"><?php _e('Helmet Size: ', 'nzih'); ?><?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h1>
    <?php $categorydesc = category_description(); if ( !empty($categorydesc) ) echo apply_filters( 'archive_meta', '<div class="archive-meta">' . $categorydesc . '</div>' ); ?>
    
    <?php while ( have_posts() ) : the_post(); ?>
    
    <div id="post-<?php the_ID(); ?>" class="taxo-helmet">
    <div class="taxo-title">
    <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('See details of this helmet', 'nzih')); ?>"><?php the_title(); ?></a></h2>
    </div> <!-- .taxo-title -->
    <div class="taxo-thumb">
    <a href="<?php the_permalink(); ?>">
    <?php the_post_thumbnail('carousel-thumbnail');?>
    </a>
    </div> <!-- .taxo-thumb -->
    </div><!-- #post-ID .taxo-helmet -->
    
    <?php endwhile; ?>

    the result can be seen at https://bit.ly/cgfj0h

    Thread Starter Pieter Bos

    (@senlin)

    miraculously this morning I tried to implement the page structure again and all of a sudden it works! Don’t know what I did wrong last night, but it must once again have been a product of working too long and until too late

    The code now is as follows (entire taxonomy-slug.php)

    <?php get_header(); ?>
    		<div id="container">
    			<div id="taxo-content">
    				<div class="pagewrap fix">
    					<div class="copy fix">
    				<h1 class="page-title"><?php _e('Helmet Size: ', 'nzih'); ?><?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo $term->name; ?></h1>
    				<?php $categorydesc = category_description(); if ( !empty($categorydesc) ) echo apply_filters( 'archive_meta', '<div class="archive-meta">' . $categorydesc . '</div>' ); ?>
    					</div><!-- .copy fix -->
    					<div class="copy fix">
    						<?php while ( have_posts() ) : the_post('orderby=ID'); ?>
    						<div id="post-<?php the_ID(); ?>" class="taxo-helmet">
    							<div class="taxo-title">
    								<h2 class="entry-title">
    									<a href="<?php the_permalink(); ?>" title="<?php printf( __('See details of this helmet', 'nzih')); ?>"><?php the_title(); ?></a>
    								</h2>
    							</div> <!-- .taxo-title -->
    							<div class="taxo-thumb">
    								<a href="<?php the_permalink(); ?>">
    									<?php the_post_thumbnail('carousel-thumbnail');?>
    								</a>
    							</div> <!-- .taxo-thumb -->
    						</div><!-- #post-ID .taxo-helmet -->
    						<?php endwhile; ?>
    						<?php if (  $wp_query->max_num_pages > 1 ) : ?>
    							<div id="nav-below" class="navigation">
    							<div class="nav-previous"><?php next_posts_link( __( 'More helmets', 'nzih' ) ); ?></div>
    							<div class="nav-next"><?php previous_posts_link( __( 'More helmets', 'nzih' ) ); ?></div>
    							</div><!-- #nav-below -->
    						<?php endif; ?>
    					</div><!-- .copy fix -->
    				</div><!-- .pagewrap fix -->
    			</div><!-- #taxo-content -->
    		</div><!-- #container -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Hey there Senlin;
    I realize that it’s been a couple of months,
    but it might interest you to know that I’ve been using a plugin that helps accomplish exactly what I think you’re asking for (including the pagination).

    Taxonomy-list-shortcode

    I can use shortcode in my pages/posts like this:
    [taxonomy-list tax=”Artist” cols=”1″ per_page=”15″ show_counts=”0″]
    and it will show 15 entries per page (list of artists)

    Thread Starter Pieter Bos

    (@senlin)

    Thanks anyway bluekachina, it’s always good to have more than one option to accomplish things!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘how to get pagination for custom taxonomies to work?’ is closed to new replies.