Pagination Not Displaying on Custom Term Archive

There where one or two problems with the code that I sorted out

Big changes

  • $number_of_terms = count( get_terms( '100list' ) ); is replaced by $number_of_terms = wp_count_terms( '100list' );. The reason is that wp_count_terms is already there to return the term count natively

  • get_categories is replaced by get_terms as get_terms accepts the offset parameter

  • Removed if (function_exists("pagination")) {. It serves no purpose, and it is the culprit that hides your pagination links.

  • Changed 'current' => $paged, to 'current' => max( 1, get_query_var('paged') ),

  • Cleaned up your indentation on the important part of your code. There seems to be closing </div>‘s missing that you have to sort out.

So, here is the code that works. I did test it on my install and works perfectly

<?php get_header(); ?>

<div class="container">
<div class="row">
<div class="col-md-12">

    <div class="row">
        <div class="col-md-9">
            <h2>Index Post Type Archive </h2>
            <hr/>
            <!-- Begin LG Screen View-->
            <span class="visible-lg">
                <article> 

                    <div class="row">
                        <?php

                        if ( get_query_var( 'paged' ) ) {
                            $paged = get_query_var('paged');
                        }elseif( get_query_var( 'page' ) ) {
                            $paged = get_query_var( 'page' );
                        }else{
                            $paged = 1;
                        }

                        $per_page = 4;
                        $number_of_terms = wp_count_terms( '100list' ); // This counts the total number terms in the taxonomy with a function)
                        $paged_offset = ($paged - 1) * $per_page;

                        $libargs = array(
                            'orderby'           => 'name',
                            'order'             => 'ASC',
                            'hide_empty'        => 0,
                            'exclude'           => array(16, 20, 22,25, 27, 28, 30, 4, 42, 7, 43 ), //* Enter ID's of parent categories to exclude from list
                            'number'            => $per_page,
                            'offset'            => $paged_offset
                        );  

                        $libcats = get_terms( '100list', $libargs);  

                        $i = 0;

                        foreach($libcats as $lc){
                            if( $i % 4 == 0 ) { ?>

                                <div class="clearfix"></div>

                            <?php }

                            $i++; ?>

                            <div class="col-lg-3">

                                <?php $termlink = get_term_link( $lc, '100list' ); ?>

                                <div class="thumbnail">
                                    <div class="caption">
                                        <br/><br/>
                                        <h1><span class="label label-warning"><?php echo  $lc->count  ?></span></h1>
                                        <p>Symbols</p>
                                        <p><a class="label label-default" href="https://wordpress.stackexchange.com/questions/158575/<?php echo $termlink; ?>"> View Group</a></p>
                                    </div>

                                    <!-- Get Image by Attachment ID Start-->

                                    <?php $attachment_id = get_field('taximage', '100list_'.$lc->term_id);
                                    if ($attachment_id) {
                                        $image = wp_get_attachment_image_src($attachment_id, 'industrygroup-img');
                                        if ($image) { ?>

                                            <img class="img-responsive" src="<?php echo $image[0]; ?>" />

                                        <?php }   

                                    }else{ ?>
                                        <img class="img-responsive" src="http://www.runningalpha.com/wp-content/uploads/2014/08/RA_logo_300px_groups.jpg" alt="<?php the_title(); ?>" />

                                    <?php } ?>

                                    <!-- Get Image by Attachment ID End-->
                                </div>      

                                    <small><p class="text-center"> <a href="https://wordpress.stackexchange.com/questions/158575/<?php echo $termlink; ?>"> <?php echo $lc->name; ?></a></p></small>

                            </div>

                        <?php } 

                        $big = 999999999; // need an unlikely integer
                        echo paginate_links( 
                            array(
                                'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                                'format'  => '/page/%#%',
                                'current' => max( 1, get_query_var('paged') ),
                                'total'   => ceil( $number_of_terms / $per_page ) // 20 items per page
                            ) 
                        );
                        ?>
                    </div>
                </article>
            </span>
        </div> <!-- End col-md-9 -->

        <div class="col-md-3">
            <?php include("sidebar100list.php"); ?>
        </div>  <!-- End col-md-3 -->

    </div><!-- End row -->
</div><!-- End Container -->
<?php get_footer(); ?>

Leave a Comment