Posts Tagged ‘get terms’

Hi all,

Hope you doing fine.

I am back again with wordpress stuff.

Some times, we need to list all category(terms) in one page.for that,it is really easy to do by function get_terms()

But problem is we need list with Pagination ūüėÄ , For that we have to pass parameter offset and number in get terms function and that’s it..!

Here is Code:

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    = 2;
$number_of_series = count( get_terms( ‘mycategory’,array(‘hide_empty’=>’0’) ) );
$offset      = $per_page * ( $paged Р1) ;

// Setup the arguments to pass in
$args = array(
‘offset’¬†¬†¬†¬†¬†¬† => $offset,
‘number’¬†¬†¬†¬†¬†¬† => $per_page,
‘hide_empty’=>’0’
);

// Gather the series
$mycategory = get_terms( ‘mycategory’, $args );

// Loop through and display the series
foreach($series as $s)
{
$theurl = get_term_link($s, ‘mycategory’);
echo “<div class=\”ser-img img\” ><a href=\”” . $theurl¬† . “\”>”. $s->name .”</a>”;

}
echo “<br />”;
$big = 999999;
echo paginate_links( array(
‘base’¬†¬†¬† => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ),
‘format’¬† => ‘?paged=%#%’,
‘current’ => $paged,
‘total’¬†¬† => ceil( $number_of_series / $per_page ) // 3 items per page
) );