?mür Yan?ko?lu
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Themes and Templates
In reply to: How do I know if a menu item has children or is a leaf?Honestly, you’re right.
I just tried to solve the problem by using the start_el function.
Your solution is more accurate because the performance is more important. Thank you for correcting.
Forum: Themes and Templates
In reply to: How do I know if a menu item has children or is a leaf?This is a good idea!
Based on this code can also be used as follows:function start_el(&$output, $item, $depth=0, $args=array()) { global $wpdb; $children_count = $wpdb->get_var( $wpdb->prepare(" SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d ", '_menu_item_menu_item_parent', $item->ID) ); if( $children_count > 0 ) { $dropdown = ' dropdown'; $dropdown_toggle = ' dropdown-toggle'; $caret = ' <b class="caret"></b>'; } [...]
Forum: Themes and Templates
In reply to: How do I know if a menu item has children or is a leaf?Hi! I also had a similar problem and figured out just before ??
The Solution:
function start_el(&$output, $item, $depth=0, $args=array()) { $parents = array(); if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) { $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); $menu_items = wp_get_nav_menu_items($menu->term_id); foreach( $menu_items as $menu_item ) { if( $menu_item->menu_item_parent != 0 ) $parents[] = $menu_item->menu_item_parent; } } $dropdown = ''; $dropdown_toggle = ''; $caret = ''; if( in_array($item->ID, $parents ) ) { $dropdown = ' dropdown'; $dropdown_toggle = ' dropdown-toggle'; $caret = ' <b class="caret"></b>'; } $active = $item->current ? ' active' : ''; [...]
The important point is →
if( in_array($item->ID, $parents ) ) { ... }
I hope that will be useful for you…Please Note: In fact, we need only has_children property in $item variable.
Viewing 3 replies - 1 through 3 (of 3 total)