基于菜单

时间:2016-03-24 10:27:50

标签: wordpress menu

我在wordpress上设置了一个菜单(类别),我想基于该菜单上的类别创建查询,每个菜单项一个查询

  • 菜单项1
  • 菜单项2
  • 菜单项3
  • 菜单项4

    $ args = array('category_name'=>'菜单项1');

    $ args = array('category_name'=>'菜单项2');

    $ args = array('category_name'=>'菜单项3');

    $ args = array('category_name'=>'菜单项4');

任何想法?

1 个答案:

答案 0 :(得分:0)

如果您正在谈论普通的WP菜单系统,您可以按照以下位置获取菜单数据:

function custom_menu_output( $theme_location ) {
    if ( ($theme_location) && ($locations = get_nav_menu_locations()) && isset($locations[$theme_location]) ) {
        $menu = get_term( $locations[$theme_location], 'nav_menu' );
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        foreach( $menu_items as $menu_item ) {
            $args = array( 'category_name' => $menu_item->title);
            //Do your query here & everything else
        }
    }
}