Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FoundationPress_top_bar_walker_custom extends Walker_Nav_Menu {
- function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
- $element->has_children = !empty( $children_elements[$element->ID] );
- $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
- $element->classes[] = ( $element->has_children && $max_depth !== 1 ) ? 'has-dropdown' : '';
- parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
- }
- function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
- $item_html = '';
- parent::start_el( $item_html, $object, $depth, $args );
- $classes = empty( $object->classes ) ? array() : (array) $object->classes;
- //custom menu-item field with the use of a plugin
- $value = get_post_meta( $object->ID, $key, true );
- if( in_array('label', $classes) ) {
- $item_html = preg_replace( '/<a[^>]*>(.*)</a>/iU', '<label>$1</label>', $item_html );
- }
- if($value[ 'menu-item-polyfield-menuitem-color' ]){
- $color = $value[ 'menu-item-polyfield-menuitem-color' ][0];
- $item_html = preg_replace('/(<ab[^><]*)>/i', '$1 style="background: #'.$color.'">', $item_html);
- }
- $output .= $item_html;
- }
- function start_lvl( &$output, $depth = 0, $args = array() ) {
- $output .= "n<ul class="sub-menu dropdown">n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement