[theme-reviewers] Theme Review Challenge and Second Opinion

Sami Keijonen sami.keijonen at foxnet.fi
Wed Mar 20 12:55:12 UTC 2013


Thanks Chip for this code snippet. It's excellent and elegant. And yet
useful.

On 20 March 2013 03:26, Chip Bennett <chip at chipbennett.net> wrote:

> By the way, I'll share this with the list, rather than in-ticket. As per
> the Codex, the best-practice implementation to add a "parent" class to
> wp_nav_menu() list items is to filter wp_nav_menu_objects. I recently used
> this method, myself:
>
> function oenology_add_menu_parent_class( $items ) {
>
> 	$parents = array();
> 	foreach ( $items as $item ) {
> 		if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
> 			$parents[] = $item->menu_item_parent;
> 		}
>
> 	}
>
>
> 	foreach ( $items as $item ) {
> 		if ( in_array( $item->ID, $parents ) ) {
> 			$item->classes[] = 'menu-item-parent';
> 		}
>
> 	}
>
>
> 	return $items;
> }
> add_filter( 'wp_nav_menu_objects', 'oenology_add_menu_parent_class' );
>
>
> I would recommend this method rather than using jQuery, though I'm not
> sure about it being *required*.
>

-- 
Sami Keijonen
Fox Holding Oy
sami.keijonen at foxnet.fi
www.foxnet.fi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20130320/9737da40/attachment.htm>


More information about the theme-reviewers mailing list