求高手幫我分析一些代碼 u! T) z& s0 d3 j
functions.php中的代碼/ Z8 s( ^, Z# L) S2 ?" e( ^0 M, x
6 }# P) l* x: G; u1 G7 P/*-----------------------------------------------------------------------------------*/
. k1 u5 ^- ~8 N0 A4 [/* Load Menu Description- o q# c2 y# C$ z( t$ b2 n
/*-----------------------------------------------------------------------------------*/3 U5 y. Y& Z0 S8 S5 _
class mts_Walker extends Walker_Nav_Menu3 Z- y/ S% p6 V! {6 d1 X* J
{3 K8 [( m! N1 z. R9 z A
function start_el(&$output, $item, $depth, $args) {% O7 r3 q5 G7 z5 J5 o. F4 R1 @1 s
global $wp_query;# `$ W9 d5 E/ p/ m* {- z9 u
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
1 i/ t; @+ R+ k* t" E6 D u0 o9 o7 V+ ^
$class_names = $value = '';8 `: } z) o) Q4 e/ O; G& S, }7 l
6 |$ k9 p. A5 t/ M) V/ }
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
/ N. _. r0 z, `% X6 p7 C% q6 ]
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
8 L' q; n. @& R& Z2 m& F* B $class_names = ' class="' . esc_attr( $class_names ) . '"';, @ N% S# F/ `% g) ] w; i
% R/ f# p6 U$ w! q6 I; a
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';1 f, T7 j. y& y$ i# {
! @. M _& V% K: Q9 {3 N% W; V $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
& w/ ~- n2 o# B. R $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
5 V2 o Y E& A5 U, j $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';6 l1 K4 {0 u) g; Y
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
" C! W5 }3 p: J: I/ x3 k: j" W% Z! \0 W1 P2 l
$item_output = $args->before;
" t( x3 p. g5 `+ H $item_output .= '<a'. $attributes .'>';9 ]/ h8 _. N+ d, d( t- G2 M
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
* l4 o9 ~# u! j. H% z $item_output .= '<br /><span class="sub">' . $item->description . '</span>';
5 \6 z& j/ K% B% w3 y/ k7 d; B) H! S& C $item_output .= '</a>';/ F/ u. m) F, L% s" g- b
$item_output .= $args->after;" @% I# }6 {; Z7 P- W& f! Z
! k; x$ ~) {3 p' C, a5 |$ n! I $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
" n' s: a# C0 ^; U }6 R/ C; A/ @8 ~- a$ S1 G7 b8 [- Z
}
/ ~9 I& |4 P/ ?+ q" L
3 B; m( y; z5 d( ^% m4 A8 Z5 Z/*-----------------------------------------------------------------------------------*/; M; e" E6 V* A" B2 l. P0 x( n
5 \; ?, m6 T( j3 f0 B Y導航菜單代碼:
9 ^. x% s. k8 u8 V x g5 B- z& ^2 m7 n% I1 ~6 b
<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>
! U4 _$ d$ R2 V6 Q) y. f+ `% W<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>
0 D% F8 a0 R' `' ]% B1 L! r<?php } else { ?>
- ]: {6 J/ C' |% U) I......+ P x& H/ n+ X) A4 n& F5 ^
為什麼導航菜單輸出的標題還是不帶描述呢?
! N! o: A; n- F" j$ V- o& Z$ O( p3 a: b, r C% b" P
8 Y( K8 Z! R4 X: \4 H像下面截圖的這種形式
# h2 X6 |( K+ s8 T. L% k9 n( P6 y* t
; Y* Q& v6 \; N$ ?
i' h {; b' z$ {, N; u5 L/ Q6 s/ H- i1 C
求高手解答,謝謝!
: \% n9 R) X/ U- U9 l9 M$ [( c8 v6 l; K8 d
|