1

我想在所有具有子项/子页面的导航项后面显示一个箭头(添加文本)“>>”。add_filter 有解决方案还是我必须自己构建菜单?

感谢帮助!

4

1 回答 1

-1

不完全是你问的......这会class="dropdown"在你的菜单中添加一个

// add a class 'dropdown' to menu items which have a sub menu
add_filter('nav_menu_css_class', 'check_for_submenu', 10, 2);
function check_for_submenu($classes, $item)
{
    global $wpdb;
    $has_children = $wpdb->get_var("SELECT COUNT(meta_id) FROM wp_postmeta WHERE meta_key='_menu_item_menu_item_parent' AND meta_value='" . $item->ID . "'");
    if ($has_children > 0)
        array_push($classes, 'dropdown'); // add the class dropdown to the current list
    return $classes;
}
于 2012-04-19T18:31:54.923 回答