WordPress主题 - 如果页面有子页面,则添加文本箭头


Wordpress theme - add text arrow if page has subpages

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

感谢您的帮助!

不完全是你问的。这会为您的菜单添加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;
}