add pagination as per wp nav menu

Posted: September 28, 2015 in Uncategorized
Tags: , ,

****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 } ?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s