2012-05-10 16 views
1

我在想,如果有一个自动顺序ID添加到每个由wp_nav_menu李输出的方式 - 所以他们基本上是wp_nav_menu定制学步车添加顺序标签号李类

<ul> 
    <li><a href="#tab1" class="tabclick active">Overview</a></li> 
    <li><a href="#tab2" class="tabclick">Specs</a></li> 
    <li><a href="#tab3" class="tabclick">More Info</a></li> 
</ul> 

我我想我已经读过关于使用步行者 - 但它超越了我的方式。

+0

它不应该是很难用普通的PHP一个简单的'foreach'做到这一点位 – janw

回答

2

OK - 找到一个解决办法基本上它建立自己的菜单 - 从这里http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items使用wp_get_nav_menu_items

请注意,这只是链接到连续的散列锚大多采取 - 但你上面的页面展示如何链接到的URL

我批注,做计数

<?php 
    // Get the nav menu based on $menu_name (same as 'theme_location' or 'menu' arg to wp_nav_menu) 
// This code based on wp_nav_menu's code to get Menu ID from menu slug 

$menu_name = 'yourmenuslug'; 
if (($locations = get_nav_menu_locations()) && isset($locations[ $menu_name ])) { 
$menu = wp_get_nav_menu_object($locations[ $menu_name ]); 
$menu_items = wp_get_nav_menu_items($menu->term_id); 
$menu_list = '<ul id="menu-' . $menu_name . '">'; 




// this bit adds the counter 
$menu_counter = 0; 
global $menu_counter; 
foreach ((array) $menu_items as $key => $menu_item) { 
$menu_counter++; 


    $title = $menu_item->title; 
    $url = $menu_item->url; 



// this bit builds the item with the sequential numbering 
    if ($menu_counter < 2) { 
      $menu_list .= '<li><a href="#tab' . $menu_counter .'" class="tabclick active" >' . $title . '</a></li>'; 
} else { 
    $menu_list .= '<li><a href="#tab' . $menu_counter .'" class="tabclick" >' . $title . '</a></li>'; 
} 

} 
$menu_list .= '</ul>'; 
} else { 
$menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>'; 
} 
// $menu_list now ready to output 
echo $menu_list; 
?>