简体   繁体   中英

Wordpress theme - add text arrow if page has subpages

I want to show an arrow (add text) ">>" behind all the navigation items that have subitems/subpages. Is there a solution with add_filter or do i have to build the menu by myself?

Thanks for help!

Not exactly what you ask.. This adds a class="dropdown" to your menu's

// 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM