求高手幫我分析一些代碼
7 Q8 O4 D8 a% H$ A1 qfunctions.php中的代碼
- q* p/ T& z/ G# Q& k* S% B& f; U0 ]: K8 ?
/*-----------------------------------------------------------------------------------*/
9 m. Q, f: T3 g ^, _( T$ D/* Load Menu Description6 ?5 S( i$ c3 k( ?/ f+ X) F3 O
/*-----------------------------------------------------------------------------------*/4 p$ N, |0 E; }" e
class mts_Walker extends Walker_Nav_Menu) ~# v4 P/ t- P( w# ~: }$ C- D
{
. Q/ k2 C, H( p& S' d2 k8 k5 ~ function start_el(&$output, $item, $depth, $args) {
. y: V; R0 F# g6 h4 X' b global $wp_query;
$ ^" N: K) D6 h. U' U $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';2 T9 g s# ]* d, ]2 n% F* W
# Z9 K. |2 i' y% i |! H $class_names = $value = '';
( E5 O! q7 h e4 z
; b* z! b8 [7 h$ ^( S/ w# v $classes = empty( $item->classes ) ? array() : (array) $item->classes;
/ I: D$ G% N1 g% v& e& N6 d8 ~9 s9 C% F& D1 R+ P) J
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
8 x$ I2 E J( F6 G) i& S6 Y $class_names = ' class="' . esc_attr( $class_names ) . '"';! X/ Q$ o. S2 e5 G
/ X" n+ G' E5 g: ]& U9 N
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; t; d9 z8 h! R+ [/ l
, _9 F: i. _7 @" I $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
4 P9 Z& [* x, |/ r* s# V $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
2 a8 m3 b; `, ]) f+ q& W5 W. f) ^ $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
! z# V9 q4 H! F3 E) s+ f $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
5 X) \" C. \/ ?7 J7 f$ [$ ?2 e
, }1 [! W: w8 \6 q2 [+ ` $item_output = $args->before;+ [3 T+ E& `8 w2 Y& `5 h3 a
$item_output .= '<a'. $attributes .'>';
) {0 i. V- N" q8 `* o. T# y $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
/ C# s8 g! K# e. f: `7 I $item_output .= '<br /><span class="sub">' . $item->description . '</span>';2 q+ x L. g& R
$item_output .= '</a>';
- n0 z) Q) P% p, H $item_output .= $args->after;5 I/ B5 C1 f4 Z0 y0 h4 K2 S+ X- z
+ O) O3 L" b. g7 M- V; d: m/ h/ ~
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );# H* l8 \9 Z% \/ F
}4 X3 _% K+ E2 f2 s4 j5 {8 H
}
& r; D6 S+ a' ?$ A" h3 Y5 m+ U. E. K
/*-----------------------------------------------------------------------------------*/1 u& {, `; l& Q0 ]3 A
/ w8 `$ @ v+ w: A, A' z導航菜單代碼:8 L# r( q$ k0 J+ k. ?/ Q
o4 v5 q% b2 Z4 ^' ?4 Q- W! k: M
<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>" ^/ R2 f# ~/ \4 f
<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>. G* c; U. J3 @4 e
<?php } else { ?>, Z( l9 e/ ]3 K2 o* \6 U, W# X
......, M& H8 T& ^, q& z! c/ L0 g
為什麼導航菜單輸出的標題還是不帶描述呢?4 ]* M) S, V$ m% }& p1 O
/ j) }1 w, G+ q( ]9 O
! w. }$ ^9 a# _6 q; E
像下面截圖的這種形式$ K: y$ D/ }: X7 B' r
; d N5 @) U! _; ^" P0 s6 M3 o
5 w% o X3 y3 E+ {: v" K& { X9 U0 i2 [5 V6 Q; i5 ~" v
求高手解答,謝謝!$ Q1 w5 P$ O6 D$ S
. T: x) S8 }( z2 x; V D
|