Display Menu Navigation Label

时间:2015-04-08 作者:Zaher

如何获得菜单中应有的导航标签

What is the code for calling or echoing the navigation label of a menu item?

我正在使用这个代码

      <?php 
    $locations = get_registered_nav_menus();
    $menus = wp_get_nav_menus();
    $menu_locations = get_nav_menu_locations();

    $location_id = \'footer_menu1\';

    if (isset($menu_locations[ $location_id ])) 
{ 
  foreach ($menus as $menu) 
  {

    if ($menu->term_id == $menu_locations[ $location_id ]) 
    {
      echo \'<h2>\'.$menu->name.\'</h2>\';
      // Get the items for this menu
      $menu_items = wp_get_nav_menu_items($menu);

      foreach ( $menu_items as $item )
      {

        $id = get_post_meta( $item->ID, \'_menu_item_object_id\', true );
        $page = get_page( $id );
        //$link = get_page_link( $id ); ?>
  <li><a href="<?php echo $item->url; ?>" > <?php echo $page->post_title; ?> </a></li>
  <?php 
      }

      break;
    }
  }
    } 
    ?>
提前感谢!

我可以替换吗<?php echo $page->post_title; ?> 具有<?php echo $menu->nav_label; ?>

1 个回复
最合适的回答,由SO网友:vadims 整理而成

代替$page->post_title; 具有$item->title; 获取菜单项的标签

结束

相关推荐

Query Taxonomy By Page Title

我想做的是在具有该分类名称的页面上显示共享该分类的帖子。例如,一个名为“PHP”的页面将显示自定义分类法“language”设置为“PHP”的所有帖子。到目前为止我所拥有的。。$secondary_loop = new WP_Query(array( \'tax_query\' => array( array( \'taxonomy\' => \'language\', \'term