求高手幫我分析一些代碼$ d9 s% h3 G& a$ C
functions.php中的代碼
9 ~) V: k: [0 K+ M+ }3 p
% c" H4 D* Z5 R% v4 x% M$ B/*-----------------------------------------------------------------------------------*/
, x; _: g) H. I/* Load Menu Description# V e# Z* E# E/ C0 E
/*-----------------------------------------------------------------------------------*/- A O9 r6 f0 W) p. o6 `# T/ D
class mts_Walker extends Walker_Nav_Menu& W' h* g7 c* k; B
{ e8 j, u( O8 b3 O
function start_el(&$output, $item, $depth, $args) {; ?1 S* V: K; T5 p0 H) y- s, F, S) x
global $wp_query;
, Y5 p1 l" u6 S% C+ V) C $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
7 E( U- N2 Y/ v+ `
) r8 l' o0 u# c# w( d $class_names = $value = '';
. D' A; v! ~" z
/ J9 z$ Y& h2 q2 H+ q( Q7 c4 ? $classes = empty( $item->classes ) ? array() : (array) $item->classes;! W& h- t' R( u! S1 [1 y
4 o. D* N8 b6 H6 s $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
# W3 D( k- e' ^& X7 v! r+ n $class_names = ' class="' . esc_attr( $class_names ) . '"';6 k# I, a* _/ } r1 N6 [: F
$ S2 y' d4 [& R/ F
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
; q3 V* G' H5 ^% K& V5 h1 J1 ~3 t
7 U" a) m3 e& k2 s5 K! g $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';5 h9 i7 l: U3 d( g
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
9 G7 o/ `$ e5 X2 l* G $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
# Q! q! [0 y( z& q. D0 Q) C $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
" Q( }9 A% C: |7 p/ i# A* L
; A( n( G# b; `6 j $item_output = $args->before;& O: J8 K8 X! a8 `& D3 ^. K! A
$item_output .= '<a'. $attributes .'>';1 z* ]9 J2 {! m& _9 }* m N4 w
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
/ U6 x7 J8 m0 G/ w( T9 Y2 o $item_output .= '<br /><span class="sub">' . $item->description . '</span>';: {( g! \! C% o4 n3 \1 P3 q6 a
$item_output .= '</a>';
( `+ l/ H1 U& f* h $item_output .= $args->after;
1 ^ K$ a8 |0 ] U6 b6 i2 M3 o4 q/ p: U( F) G( d- x a3 V% F7 q
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
1 i4 C- _/ M- ^! u9 K }6 u' D6 d6 j+ H2 B
}
" X, @& I) E# M1 G& z
* C; E7 A, y7 V4 t+ P$ ]/*-----------------------------------------------------------------------------------*/; I8 x3 G# s, U# i
2 j$ D1 m7 a$ S8 J+ C
導航菜單代碼:: ?8 |& A2 V3 l6 |; Z- N
N) F8 T5 P/ W
<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>! K' ~/ q4 y1 }8 C5 N
<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>1 y' ~- C, V: L" ]
<?php } else { ?>
3 s2 G9 H M" M......' s/ G- Q0 f0 L. Y; r3 G3 K) P( A
為什麼導航菜單輸出的標題還是不帶描述呢? J' Q2 W/ c0 m% t0 b/ }3 k
7 q, `" Z3 a% G# p/ @; Y
/ n1 w* l; O" d: a' @" k% o像下面截圖的這種形式
/ ^( Z/ ~% c+ z1 }+ y
) ]4 g/ q) S) z7 d9 X* T8 e% m, B, @
S5 n4 ~$ \. U3 Q9 Q! w, L
求高手解答,謝謝!
" C9 B' j) [( {0 _6 z9 s" z
( L! _5 h6 x- j! i) K* j, U |