Posts Tagged ‘pagination’

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
) );

 

****WP MENU NAVIGATE/Pagiantion****************/
$linkarray=array();
$urlarray=array();
$locations = get_nav_menu_locations();

$menu = wp_get_nav_menu_object($locations[‘primary’]);¬† //Get menu items that menu location is set to ‘primary’
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( ‘order’ => ‘DESC’ ) );

$i=-1;
foreach ( $menuitems as $item ){
if($item->type !=’custom’){
$i++;
$id = get_post_meta($item->ID,’_menu_item_object_id’,true).'<br />’;
$page = get_page($id);
$link = get_page_link($id);
$linkarray.=$id.”,”;
$urlarray.=$link.”,”;

if ($id==$post->ID){
echo ‘previd :’.$previd=$i-1;
$nextid=$i+1;
}
}
}

$linkarray=explode(‘,’,$linkarray);
$urlarray=explode(‘,’,$urlarray);

$nextid=$urlarray[$nextid];
if (empty($nextid)){
$nextid=$urlarray[0];
}
if($previd>0){
$previd=$urlarray[$previd];
if (empty($previd)){
$previd=$urlarray[$i];
}
}
?>
<a href=”<?php echo $nextid; ?>”>Next Item</a>
<?php if($previd>0){ ?>
<a href=”<?php echo $previd; ?>”>Previous Item</a>
<?php } ?>