2012-05-10 21 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; 
?>