好的,所以我有一个Walker课程。我正在尝试仅向具有SUB MENU的菜单项添加下拉箭头。
箭头图标:<br><span class="nav-desc" id="nav-desc-show"><i class="fa fa-caret-down" aria-hidden="true"></i> </span>
问题目前我已经获得了每个菜单项的箭头,因为我不知道如何更改它,所以它只显示带有子菜单的菜单项。
自定义原色nav.php
<?php
class Nav_Walker_Nav_Menu extends Walker_Nav_Menu{
function start_el(&$output, $item, $depth, $args){
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 = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
/* adding the class name for sub menu custom - */
// $output .= "\n$indent<ul class=\"sub-menu-about\">\n";
$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 ) .'"' : '';
$description = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'><span data-hover="'. $item->title .'">';
$item_output .=$args->link_before .apply_filters( 'the_title', $item->title, $item->ID );
$item_output .= $description.$args->link_after;
/* Add span add in this nav menu - custom* */
$item_output.= '<br><span class="nav-desc" id="nav-desc-show"><i class="fa fa-caret-down" aria-hidden="true"></i> </span>';
$item_output .= '</span></a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
?>
的header.php
<?php
/**
* The header for our theme
*
* This is the template that displays all of the <head> section and everything up until <div id="content">
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package radian3
*/
?>
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page" class="site">
<a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'radian3' ); ?></a>
<header id="masthead" class="site-header">
<div class="header-wrap">
<div class="site-branding">
<?php the_custom_logo(); /* Gets the custom logo */ ?>
<div class="site-branding-text">
<?php if ( is_front_page() && is_home() ) : ?>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<?php else : ?>
<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
<?php
endif;
$description = get_bloginfo( 'description', 'display' );
if ( $description || is_customize_preview() ) : ?>
<p class="site-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
<?php
endif; ?>
</div>
</div><!-- .site-branding -->
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'radian3' ); ?></button>
<?php
$walker = new Nav_Walker_Nav_Menu;
$args = array(
'theme_location' => 'primary',
'menu_id' => 'primary-menu',
'walker' => $walker
);
wp_nav_menu($args);
?>
</nav><!-- #site-navigation -->
</div>
</header><!-- #masthead -->
<div id="content" class="site-content">
答案 0 :(得分:0)
也许尝试这样的事情
if($depth && $args->has_children)
{
/* Add span add in this nav menu - custom* */
$item_output.= '<br><span class="nav-desc" id="nav-desc-show"><i class="fa fa-caret-down" aria-hidden="true"></i> </span>';
}