求高手幫我分析一些代碼) k- r/ N, y6 |* m& |# @3 z
functions.php中的代碼
0 L4 d2 h1 M$ q7 e& T( u5 |" z9 F' K: R8 V
/*-----------------------------------------------------------------------------------*/1 m% {, Y0 W+ @ p& S8 f! ?7 X
/* Load Menu Description) g4 z" ~/ d/ s
/*-----------------------------------------------------------------------------------*/0 q D5 S7 {5 o% c
class mts_Walker extends Walker_Nav_Menu0 A( V' ~ ]4 Y% R; x3 O
{4 ], R$ s0 I: U- e/ \4 G% b9 q
function start_el(&$output, $item, $depth, $args) {: G) @: G9 E3 t% ]) m4 M+ A3 j
global $wp_query;
+ _: C: P. [' b8 r0 L' p $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
3 M! G/ @8 {% u# B; C& P5 J+ [1 q( o0 t+ z, R! C" A- N
$class_names = $value = '';# N0 i! E5 L% I3 |$ ?* ?
" h- {/ M% I9 T5 t( z $classes = empty( $item->classes ) ? array() : (array) $item->classes;
4 |0 z$ ?$ H4 z. H4 z6 N0 i. I7 _# w' g" \
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
. B/ I* M9 W0 g; f9 ]& l% p $class_names = ' class="' . esc_attr( $class_names ) . '"';
6 R1 o# O( N2 A$ Z% D$ b7 n V( F, m/ m) C
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';! {! ^/ z: w# k
8 a) \1 D T4 q5 X/ }3 K) @ $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';4 T2 \) l3 x% m; x6 A% u, y5 {$ e
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';! ]& I) u& F. d0 ?
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';# H, i$ U* v. e' G$ h
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
! I0 ]1 F' c& C. r2 H8 @2 [. i6 a
3 i8 h$ v- O6 m- m) I# n $item_output = $args->before;
, ?" h- t9 \! P9 u" b $item_output .= '<a'. $attributes .'>';
, b! v# m. k4 j0 Z% h+ f $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;* i% u: _1 S# Q/ R* b- |7 ~' Q7 z
$item_output .= '<br /><span class="sub">' . $item->description . '</span>';# r" t( n& k9 I# C% i% L9 P# M+ _
$item_output .= '</a>';( j- t! b. P! G e& O& A
$item_output .= $args->after;
( j# D# u" h; S1 U% y. K
5 B# Z( C# e1 i# n, V $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );& ~: {+ ]7 b7 i& Y% E# X
}3 `, k' a5 {% i3 S4 t
}6 x- b8 y0 G, b! G1 b) @3 ?- K
G5 A& w# j, u! D1 x/*-----------------------------------------------------------------------------------*/
" ]8 P# T5 p$ b8 b) U1 q4 Q# Y$ O& K$ d; t
導航菜單代碼:
" x( [. ?! U1 S# Q
; X) ]1 c" b" z: A<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>
7 s' Y0 N4 _7 X' ^<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>! C- e; e) I& ~. j2 m+ r4 ~
<?php } else { ?>% J' o5 \+ Z7 F. O
......
' u8 Z, u# w. z6 k為什麼導航菜單輸出的標題還是不帶描述呢?
: M5 S, P0 e' N) k1 K+ A" _4 c* Q
9 B& {/ V4 Q' N+ ]
1 w6 a( T: J9 o4 b; U3 ?0 j像下面截圖的這種形式
9 e s5 [: O0 a- j; |3 U0 f
% G% A- V9 V' e* ?
8 U" q k+ ~1 v3 q1 X. U: P# b& i, x7 Z
4 P, U9 \' Z9 w, }& z求高手解答,謝謝!
, J2 h3 D9 n- S5 |4 ?. t% v9 O( r3 f! _/ A
|