php - Submenu adding wordpress -
i have wordpress page has following menu layout.
- primary menu
- sub menu
- primary
- list item
i add submenu submenu (submenuception)
- primary
- sub menu
- sub sub menu
- sub menu
my current theme doesn't support , how can add via code. can me pointing @ right direction. thanks!
added code of themes nav-menu-template:
<?php /** * navigation menu template functions * * @package wordpress * @subpackage nav_menus * @since 3.0.0 */ /** * create html list of nav menu items. * * @since 3.0.0 * @uses walker */ class walker_nav_menu extends walker { /** * class handles. * * @see walker::$tree_type * @since 3.0.0 * @var string */ public $tree_type = array( 'post_type', 'taxonomy', 'custom' ); /** * database fields use. * * @see walker::$db_fields * @since 3.0.0 * @todo decouple this. * @var array */ public $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id' ); /** * starts list before elements added. * * @see walker::start_lvl() * * @since 3.0.0 * * @param string $output passed reference. used append additional content. * @param int $depth depth of menu item. used padding. * @param array $args array of arguments. @see wp_nav_menu() */ public function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "\n$indent<ul class=\"sub-menu\">\n"; } /** * ends list of after elements added. * * @see walker::end_lvl() * * @since 3.0.0 * * @param string $output passed reference. used append additional content. * @param int $depth depth of menu item. used padding. * @param array $args array of arguments. @see wp_nav_menu() */ public function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } /** * start element output. * * @see walker::start_el() * * @since 3.0.0 * * @param string $output passed reference. used append additional content. * @param object $item menu item data object. * @param int $depth depth of menu item. used padding. * @param array $args array of arguments. @see wp_nav_menu() * @param int $id current item id. */ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->id; /** * filter css class(es) applied menu item's list item element. * * @since 3.0.0 * @since 4.1.0 `$depth` parameter added. * * @param array $classes css classes applied menu item's `<li>` element. * @param object $item current menu item. * @param array $args array of {@see wp_nav_menu()} arguments. * @param int $depth depth of menu item. used padding. */ $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; /** * filter id applied menu item's list item element. * * @since 3.0.1 * @since 4.1.0 `$depth` parameter added. * * @param string $menu_id id applied menu item's `<li>` element. * @param object $item current menu item. * @param array $args array of {@see wp_nav_menu()} arguments. * @param int $depth depth of menu item. used padding. */ $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->id, $item, $args, $depth ); $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; $output .= $indent . '<li' . $id . $class_names .'>'; $atts = array(); $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : ''; $atts['target'] = ! empty( $item->target ) ? $item->target : ''; $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : ''; $atts['href'] = ! empty( $item->url ) ? $item->url : ''; /** * filter html attributes applied menu item's anchor element. * * @since 3.6.0 * @since 4.1.0 `$depth` parameter added. * * @param array $atts { * html attributes applied menu item's `<a>` element, empty strings ignored. * * @type string $title title attribute. * @type string $target target attribute. * @type string $rel rel attribute. * @type string $href href attribute. * } * @param object $item current menu item. * @param array $args array of {@see wp_nav_menu()} arguments. * @param int $depth depth of menu item. used padding. */ $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth ); $attributes = ''; foreach ( $atts $attr => $value ) { if ( ! empty( $value ) ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); $attributes .= ' ' . $attr . '="' . $value . '"'; } } $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; /** filter documented in wp-includes/post-template.php */ $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->id ) . $args->link_after; $item_output .= '</a>'; $item_output .= $args->after; /** * filter menu item's starting output. * * menu item's starting output includes `$args->before`, opening `<a>`, * menu item's title, closing `</a>`, , `$args->after`. currently, there * no filter modifying opening , closing `<li>` menu item. * * @since 3.0.0 * * @param string $item_output menu item's starting html output. * @param object $item menu item data object. * @param int $depth depth of menu item. used padding. * @param array $args array of {@see wp_nav_menu()} arguments. */ $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } /** * ends element output, if needed. * * @see walker::end_el() * * @since 3.0.0 * * @param string $output passed reference. used append additional content. * @param object $item page data object. not used. * @param int $depth depth of page. not used. * @param array $args array of arguments. @see wp_nav_menu() */ public function end_el( &$output, $item, $depth = 0, $args = array() ) { $output .= "</li>\n"; } } // walker_nav_menu /** * displays navigation menu. * * @since 3.0.0 * * @param array $args { * optional. array of nav menu arguments. * * @type string $menu desired menu. accepts (matching in order) id, slug, name. default empty. * @type string $menu_class css class use ul element forms menu. default 'menu'. * @type string $menu_id id applied ul element forms menu. * default menu slug, incremented. * @type string $container whether wrap ul, , wrap with. default 'div'. * @type string $container_class class applied container. default 'menu-{menu slug}-container'. * @type string $container_id id applied container. default empty. * @type callback|bool $fallback_cb if menu doesn't exists, callback function fire. * default 'wp_page_menu'. set false no fallback. * @type string $before text before link text. default empty. * @type string $after text after link text. default empty. * @type string $link_before text before link. default empty. * @type string $link_after text after link. default empty. * @type bool $echo whether echo menu or return it. default true. * @type int $depth how many levels of hierarchy included. 0 means all. default 0. * @type object $walker instance of custom walker class. default empty. * @type string $theme_location theme location used. must registered register_nav_menu() * in order selectable user. * @type string $items_wrap how list items should wrapped. default ul id , class. * uses printf() format numbered placeholders. * } * @return mixed menu output if $echo false, false if there no items or no menu found. */ function wp_nav_menu( $args = array() ) { static $menu_id_slugs = array(); $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'depth' => 0, 'walker' => '', 'theme_location' => '' ); $args = wp_parse_args( $args, $defaults ); /** * filter arguments used display navigation menu. * * @since 3.0.0 * * @see wp_nav_menu() * * @param array $args array of wp_nav_menu() arguments. */ $args = apply_filters( 'wp_nav_menu_args', $args ); $args = (object) $args; /** * filter whether short-circuit wp_nav_menu() output. * * returning non-null value filter short-circuit * wp_nav_menu(), echoing value if $args->echo true, * returning value otherwise. * * @since 3.9.0 * * @see wp_nav_menu() * * @param string|null $output nav menu output short-circuit with. default null. * @param object $args object containing wp_nav_menu() arguments. */ $nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args ); if ( null !== $nav_menu ) { if ( $args->echo ) { echo $nav_menu; return; } return $nav_menu; } // nav menu based on requested menu $menu = wp_get_nav_menu_object( $args->menu ); // nav menu based on theme_location if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); // first menu has items if still can't find menu if ( ! $menu && !$args->theme_location ) { $menus = wp_get_nav_menus(); foreach ( $menus $menu_maybe ) { if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { $menu = $menu_maybe; break; } } } // if menu exists, items. if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); /* * if no menu found: * - fall (if 1 specified), or bail. * * if no menu items found: * - fall back, if no theme location specified. * - otherwise, bail. */ if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) return call_user_func( $args->fallback_cb, (array) $args ); if ( ! $menu || is_wp_error( $menu ) ) return false; $nav_menu = $items = ''; $show_container = false; if ( $args->container ) { /** * filter list of html tags valid use menu containers. * * @since 3.0.0 * * @param array $tags acceptable html tags use menu containers. * default array containing 'div' , 'nav'. */ $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); if ( in_array( $args->container, $allowed_tags ) ) { $show_container = true; $class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"'; $id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : ''; $nav_menu .= '<'. $args->container . $id . $class . '>'; } } // set $menu_item variables _wp_menu_item_classes_by_context( $menu_items ); $sorted_menu_items = $menu_items_with_children = array(); foreach ( (array) $menu_items $menu_item ) { $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; if ( $menu_item->menu_item_parent ) $menu_items_with_children[ $menu_item->menu_item_parent ] = true; } // add menu-item-has-children class applicable if ( $menu_items_with_children ) { foreach ( $sorted_menu_items &$menu_item ) { if ( isset( $menu_items_with_children[ $menu_item->id ] ) ) $menu_item->classes[] = 'menu-item-has-children'; } } unset( $menu_items, $menu_item ); /** * filter sorted list of menu item objects before generating menu's html. * * @since 3.1.0 * * @param array $sorted_menu_items menu items, sorted each menu item's menu order. * @param object $args object containing wp_nav_menu() arguments. */ $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args ); $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args ); unset($sorted_menu_items); // attributes if ( ! empty( $args->menu_id ) ) { $wrap_id = $args->menu_id; } else { $wrap_id = 'menu-' . $menu->slug; while ( in_array( $wrap_id, $menu_id_slugs ) ) { if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) $wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id ); else $wrap_id = $wrap_id . '-1'; } } $menu_id_slugs[] = $wrap_id; $wrap_class = $args->menu_class ? $args->menu_class : ''; /** * filter html list content navigation menus. * * @since 3.0.0 * * @see wp_nav_menu() * * @param string $items html list content menu items. * @param object $args object containing wp_nav_menu() arguments. */ $items = apply_filters( 'wp_nav_menu_items', $items, $args ); /** * filter html list content specific navigation menu. * * @since 3.0.0 * * @see wp_nav_menu() * * @param string $items html list content menu items. * @param object $args object containing wp_nav_menu() arguments. */ $items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args ); // don't print markup if there no items @ point. if ( empty( $items ) ) return false; $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); unset( $items ); if ( $show_container ) $nav_menu .= '</' . $args->container . '>'; /** * filter html content navigation menus. * * @since 3.0.0 * * @see wp_nav_menu() * * @param string $nav_menu html content navigation menu. * @param object $args object containing wp_nav_menu() arguments. */ $nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args ); if ( $args->echo ) echo $nav_menu; else return $nav_menu; } /** * add class property classes current context, if applicable. * * @access private * @since 3.0.0 * * @param array $menu_items current menu item objects add class property information. */ function _wp_menu_item_classes_by_context( &$menu_items ) { global $wp_query, $wp_rewrite; $queried_object = $wp_query->get_queried_object(); $queried_object_id = (int) $wp_query->queried_object_id; $active_object = ''; $active_ancestor_item_ids = array(); $active_parent_item_ids = array(); $active_parent_object_ids = array(); $possible_taxonomy_ancestors = array(); $possible_object_parents = array(); $home_page_id = (int) get_option( 'page_for_posts' ); if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) { foreach ( (array) get_object_taxonomies( $queried_object->post_type ) $taxonomy ) { if ( is_taxonomy_hierarchical( $taxonomy ) ) { $term_hierarchy = _get_term_hierarchy( $taxonomy ); $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) ); if ( is_array( $terms ) ) { $possible_object_parents = array_merge( $possible_object_parents, $terms ); $term_to_ancestor = array(); foreach ( (array) $term_hierarchy $anc => $descs ) { foreach ( (array) $descs $desc ) $term_to_ancestor[ $desc ] = $anc; } foreach ( $terms $desc ) { { $possible_taxonomy_ancestors[ $taxonomy ][] = $desc; if ( isset( $term_to_ancestor[ $desc ] ) ) { $_desc = $term_to_ancestor[ $desc ]; unset( $term_to_ancestor[ $desc ] ); $desc = $_desc; } else { $desc = 0; } } while ( ! empty( $desc ) ); } } } } } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); $term_to_ancestor = array(); foreach ( (array) $term_hierarchy $anc => $descs ) { foreach ( (array) $descs $desc ) $term_to_ancestor[ $desc ] = $anc; } $desc = $queried_object->term_id; { $possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc; if ( isset( $term_to_ancestor[ $desc ] ) ) { $_desc = $term_to_ancestor[ $desc ]; unset( $term_to_ancestor[ $desc ] ); $desc = $_desc; } else { $desc = 0; } } while ( ! empty( $desc ) ); } $possible_object_parents = array_filter( $possible_object_parents ); $front_page_url = home_url(); foreach ( (array) $menu_items $key => $menu_item ) { $menu_items[$key]->current = false; $classes = (array) $menu_item->classes; $classes[] = 'menu-item'; $classes[] = 'menu-item-type-' . $menu_item->type; $classes[] = 'menu-item-object-' . $menu_item->object; // if menu item corresponds taxonomy term currently-queried non-hierarchical post object if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { $active_parent_object_ids[] = (int) $menu_item->object_id; $active_parent_item_ids[] = (int) $menu_item->db_id; $active_object = $queried_object->post_type; // if menu item corresponds currently-queried post or taxonomy object } elseif ( $menu_item->object_id == $queried_object_id && ( ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object ) ) ) { $classes[] = 'current-menu-item'; $menu_items[$key]->current = true; $_anc_id = (int) $menu_item->db_id; while( ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && ! in_array( $_anc_id, $active_ancestor_item_ids ) ) { $active_ancestor_item_ids[] = $_anc_id; } if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) { // compat classes pages match wp_page_menu() $classes[] = 'page_item'; $classes[] = 'page-item-' . $menu_item->object_id; $classes[] = 'current_page_item'; } $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; // if menu item corresponds currently-requested url } elseif ( 'custom' == $menu_item->object ) { $_root_relative_current = untrailingslashit( $_server['request_uri'] ); $current_url = set_url_scheme( 'http://' . $_server['http_host'] . $_root_relative_current ); $raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; $item_url = untrailingslashit( $raw_item_url ); $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) ); if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { $classes[] = 'current-menu-item'; $menu_items[$key]->current = true; $_anc_id = (int) $menu_item->db_id; while( ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && ! in_array( $_anc_id, $active_ancestor_item_ids ) ) { $active_ancestor_item_ids[] = $_anc_id; } if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) { // compat home link match wp_page_menu() $classes[] = 'current_page_item'; } $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; $active_parent_object_ids[] = (int) $menu_item->post_parent; $active_object = $menu_item->object; // give front page item current-menu-item class when query arguments involved } elseif ( $item_url == $front_page_url && is_front_page() ) { $classes[] = 'current-menu-item'; } if ( untrailingslashit($item_url) == home_url() ) $classes[] = 'menu-item-home'; } // back-compat wp_page_menu: add "current_page_parent" static home page link non-page query if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ) $classes[] = 'current_page_parent'; $menu_items[$key]->classes = array_unique( $classes ); } $active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) ); $active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) ); $active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) ); // set parent's class foreach ( (array) $menu_items $key => $parent_item ) { $classes = (array) $parent_item->classes; $menu_items[$key]->current_item_ancestor = false; $menu_items[$key]->current_item_parent = false; if ( isset( $parent_item->type ) && ( // ancestral post object ( 'post_type' == $parent_item->type && ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) && in_array( $parent_item->object_id, $queried_object->ancestors ) && $parent_item->object != $queried_object->id ) || // ancestral term ( 'taxonomy' == $parent_item->type && isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) && in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) && ( ! isset( $queried_object->term_id ) || $parent_item->object_id != $queried_object->term_id ) ) ) ) { $classes[] = empty( $queried_object->taxonomy ) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor'; } if ( in_array( intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) { $classes[] = 'current-menu-ancestor'; $menu_items[$key]->current_item_ancestor = true; } if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) { $classes[] = 'current-menu-parent'; $menu_items[$key]->current_item_parent = true; } if ( in_array( $parent_item->object_id, $active_parent_object_ids ) ) $classes[] = 'current-' . $active_object . '-parent'; if ( 'post_type' == $parent_item->type && 'page' == $parent_item->object ) { // compat classes pages match wp_page_menu() if ( in_array('current-menu-parent', $classes) ) $classes[] = 'current_page_parent'; if ( in_array('current-menu-ancestor', $classes) ) $classes[] = 'current_page_ancestor'; } $menu_items[$key]->classes = array_unique( $classes ); } } /** * retrieve html list content nav menu items. * * @uses walker_nav_menu create html list content. * @since 3.0.0 * @see walker::walk() parameters , return description. */ function walk_nav_menu_tree( $items, $depth, $r ) { $walker = ( empty($r->walker) ) ? new walker_nav_menu : $r->walker; $args = array( $items, $depth, $r ); return call_user_func_array( array($walker, 'walk'), $args ); } /** * prevents menu item id being used more once. * * @since 3.0.1 * @access private */ function _nav_menu_item_id_use_once( $id, $item ) { static $_used_ids = array(); if ( in_array( $item->id, $_used_ids ) ) return ''; $_used_ids[] = $item->id; return $id; } add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 );
i can't add in comments, try adding sub sub menu in wordpress, , in style.css, or wherever adding css try putting this:
.main-menu li ul.sub-menu li ul{ margin:0; padding: 0 15px; background: url("images/submenu-top-bg.jpg") top left repeat-x #f3f3f3; top: 0; left: 100%; } .main-menu li ul.sub-menu li ul li{ float:left; list-style:none; } .main-menu li ul.sub-menu li ul > li{ float: none; display: block; padding: 0; margin: 0; width: auto; background: none; } .main-menu li ul.sub-menu li ul li a{ padding: 8px 0px 12px 0!important; } .main-menu li ul.sub-menu li ul li:first-child a{ padding: 14px 0px 10px 0!important; } .main-menu li ul.sub-menu li ul li a:hover{ display:list-item; overflow:hidden; text-decoration:none; font-size:13px; line-height:10px; font-weight:normal; text-shadow:1px 1px #fff; white-space:nowrap; } .main-menu li ul.sub-menu li ul li span{ font-family:'open sans',sans-serif; }
and see if second level menu working.
edit
the code has been changed fix issue.
edit 2
since jquery messing stuff up, can add this:
.main-menu li ul.sub-menu li:hover ul{ display:block!important; } .main-menu li ul.sub-menu:before{ content:""; position:absolute; top:0; right:100%; width:20px; height:100%; }
and in master.js file on line 58 change code this:
function jsddm_open() { jsddm_canceltimer(); ddmenuitem = jquery(this).find('> ul').slidedown('fast'); }
this make sub menu shows on hover.
it's ugly solution, it's something. fiddle around js file , tweak works better.
Comments
Post a Comment