add pagination in wordpress page template

Question

I am using custom page to display my taxonomy terms the terms are displaying fine but
i dont want the terms to all show in one page i want 2 terms per page but the pagination is not working and its showing all the terms on 1 page

this is the code that i am using custom page

<?php /*Template Name: terms-List*/ ?>
<?php get_header();?>
<div class="container">
<header class="page-header">
<h1 class="page-title">terms list</h1>
</header>
<div class="container">
<div class="row">
<?php 
$terms = get_terms([
'taxonomy' => 'books',
'hide_empty' => false,
]);
foreach ( $terms as $term) {
?>
<div class="col-lg-5th col-md-5th col-sm-5th col-xs-5th">
<div class="block-item">
<div class="hover"></div>
<a href="<?php echo get_term_link($term);?>" title="<?php echo $term->name;?>">
<?php $poster = get_term_meta( $term->term_id, 'photo-url', true );
if($poster){?>
<img width="200" height="283" src="<?php echo $poster; ?>" class="attachment-movie size-movie wp-post-image" alt=""> 
<?php
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-thumbnail.png" alt="" />
<?php } ?>
<div class="title"><?php echo $term->name; ?></div>
</a>
</div>
</div>
<?php 
} 
?>
</div>
<div class="pagination">
<?php wpbeginner_numeric_posts_nav(); ?>
</div>
</div>
</div>
<?php get_footer();?>

I am using wpbeginner’s pagination code which i have put in functions.php.

<?php
function wpbeginner_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max   = intval( $wp_query->max_num_pages );
if ( $paged >= 1 )
$links[] = $paged;
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<ul>' . "n";
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "n", get_previous_posts_link('«') );
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "n", get_next_posts_link('»') );
echo '</ul>' . "n";
}
?>

and this is the code for the taxonomy that i am getting the terms form

<?php
add_action( 'init', 'create_series_hierarchical_taxonomy', 0 ); 
function create_series_hierarchical_taxonomy() {
   $labels = array(
    'name' => _x( 'books', 'taxonomy general name' ),
    'singular_name' => _x( 'books', 'taxonomy singular name' ),
    'search_items' =>  __( 'search books' ),
    'all_items' => __( 'all books' ),
    'parent_item' => __( 'parent book' ),
    'parent_item_colon' => __( 'parent book' ),
    'edit_item' => __( 'edit books' ), 
    'update_item' => __( 'update books' ),
    'add_new_item' => __( 'add more books' ),
    'new_item_name' => __( 'book name' ),
    'menu_name' => __( 'books' ),
  );     
  register_taxonomy('books',array('books'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'books' ),
  ));
 
}
?>

It is possible to make a pagination

0
, , , , MY Design 5 months 0 Answers 56 views 0

Leave an answer