Posts Tagged ‘wp nav menu’

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

Hi all,

recently I just try to add class in li tag in wp nav menu.After some search I got this:

Filter Name : nav_menu_css_class

 

function li_class($classes, $item, $args) {
$classes[] = ‘YOUR_CLASS_NAME’;  // add our class name
return $classes;
}
add_filter(‘nav_menu_css_class’,’li_class’,1,3);