求高手幫我分析一些代碼6 j- ^ a( h+ O
functions.php中的代碼2 k1 c$ Z( V: E+ U, I
9 d, O$ F/ n* g) }$ J
/*-----------------------------------------------------------------------------------*/7 z5 ^: f# k# \7 v
/* Load Menu Description9 G& n! z) m" V3 ~! u8 x, I7 j; C
/*-----------------------------------------------------------------------------------*/
: u$ e _+ w. m( e) c$ mclass mts_Walker extends Walker_Nav_Menu
) |1 @7 F3 o4 F: ]/ F% ]0 T7 H+ V- i{
3 I- \1 B8 J( O* }! Y function start_el(&$output, $item, $depth, $args) {! a* K; V8 H( W9 q( E
global $wp_query;
$ ^9 a: K) W: j' j $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
2 b) W! R9 j5 V. ]
5 [6 C' U7 n5 z0 G- d0 w $class_names = $value = '';! b+ V1 J6 u# b
3 I0 @2 w; x$ p" x9 G3 o1 j $classes = empty( $item->classes ) ? array() : (array) $item->classes;
; Z1 K$ K4 ]: p* M& I* k8 f& U* b6 f; h
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );# K; }- E% K H) |) W! }. U
$class_names = ' class="' . esc_attr( $class_names ) . '"';
1 J0 @& X2 G+ G" H, V5 T9 _5 q/ I3 c& b* Z6 k5 r
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';" @( Y/ y7 f' t/ o, F7 J
7 Z+ F1 |8 r: s" Q& @( h! V $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';2 ^! e$ `, n: I* |
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$ p# B4 s- n$ m" n" c, ?* J1 s, V $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
& H3 m2 k6 i' V' ~3 d/ K( }9 I $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';% D5 J: F/ j% K% K
* ?, w+ Z( x* [- k. Q- ] $item_output = $args->before;8 P% V7 d: Z( s$ o: W
$item_output .= '<a'. $attributes .'>';/ N- ]0 [/ o$ X' p; F" l
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;9 `, W0 P# Q6 r1 N5 H2 i9 O, \
$item_output .= '<br /><span class="sub">' . $item->description . '</span>';
! x3 ~. l; h0 c* J5 b $item_output .= '</a>';
4 A% q+ H9 I% U# @; h $item_output .= $args->after;* m0 A" P/ q" U& _. m
, K* q" C, f% u# C$ n; Z1 F" R+ |! v# \
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );# Q/ A( U4 w! X+ }
}3 m) L* n" r* k& v
}
# B' D- |8 F2 N: h. `& W0 @7 S6 ?/ Z4 C. r' k$ g- z- |4 a U
/*-----------------------------------------------------------------------------------*/- s r. k, ^4 t2 _% S
: [6 G6 J) ?1 l! Q. k& {導航菜單代碼:* }& I0 M& ]& `
1 O* I$ s, X6 J; k$ ]/ Y! |<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>
7 O# x: u2 N. E2 `4 G+ Z" ^<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>
' H7 S* z# h4 B V: ] ~, n# M3 @<?php } else { ?>& E9 C% N! [# s; X/ ?5 A0 [
......) p L# Y, X5 U) G: J7 n5 V1 W
為什麼導航菜單輸出的標題還是不帶描述呢?
5 s/ |; R8 f! h2 ?# {
* M1 }3 W* r( x2 f+ U) V# }+ L- c: g2 S! T5 D: O% `* {$ T' f
像下面截圖的這種形式
- u. V% @5 G" `7 x* i
n' }6 x# j4 J; Q' q
4 _: F& T0 U- _) J( Z$ K! w# B- a+ w! r. L2 u
求高手解答,謝謝!* D! [) S9 h! b7 D
9 m' L& |/ B& I7 \
|