首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >显示活动菜单项

显示活动菜单项
EN

Stack Overflow用户
提问于 2015-04-22 13:30:07
回答 1查看 691关注 0票数 0

我有个问题,不知道怎么解决。我需要显示当前活动菜单的下拉菜单。我有以下代码:

代码语言:javascript
代码运行次数:0
运行
复制
Class Description_Walker extends Walker_Nav_Menu {


function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
$id_field = $this->db_fields['id'];
if ( is_object( $args[0] ) ) {
  $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
}
return parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}

function start_lvl( &$output , $depth = 0 , $args = array() ) {
    $indent = str_repeat( "\t", $depth );
    $output .= "\n$indent<ul class=\"v-dropdown \">\n";
}



     function start_el(&$output, $item, $depth = 0, $args = array(), $current_object_id = 0)
  {
       global $wp_query;
       $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

       $class_names = $value = '';

       $classes = empty( $item->classes ) ? array() : (array) $item->classes;

       $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );

       $class_names = ' '. esc_attr( $class_names ) . '';


       $output .= $indent . '<li >';
       $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
       $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
       $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
       $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
       $prepend='';

       $append = '';
       $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';


        $item_output = $args->before;

        if ( $args->has_children ) {
            $append="&nbsp;&#9662;";
                 $item_output .= '<a class="dropdown" data-hover="&nbsp">';
                 $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
        $item_output .= $description.$args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        } else {
                 $item_output .= '<a class="'.esc_attr( $class_names ).'" '. $attributes .' data-hover="&nbsp'.preg_replace('&nbsp;', $item->title).$append.'" >';
                 $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
        $item_output .= $description.$args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        }


        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );


        }

}

网站是这样的:site

当子菜单处于活动状态时,我需要显示ul class=“v-下拉菜单”。请帮帮我。

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-22 15:21:10

我会这么做的。

您可以将您的<header class="relative">交换为以下内容:

代码语言:javascript
代码运行次数:0
运行
复制
<header class="relative <?php if ( $post->post_parent == '47' ) { ?>show-menu<?php } ?>" >

替换“47”所在的父页ID。如果您使用父id设置了这些页面,则为。

如果没有,您可以这样做,使用相同的<header class="relative">设置。

代码语言:javascript
代码运行次数:0
运行
复制
<header class="relative <?php if ( is_page('services') || is_page('corporate-advisory') || is_page('audit-and-accounting') || is_page ('international-orientation-for-smi')) { ?>show-menu<?php } ?>" >

然后,只需在css中添加如下css类:

代码语言:javascript
代码运行次数:0
运行
复制
.show-menu ul li:nth-of-type(3) .v-dropdown {display: block; }

我在本地设置了一个测试,我认为这两种方法都可能适用于您。如果我需要澄清的话请告诉我。

编辑:,我在css中添加了一个psuedo类,目标是“.v-下拉列表”的第一个实例,以便只有第一个菜单打开。

编辑2:我更新了答案以反映正确的css,这有助于AnmA解决问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29799145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档