求高手幫我分析一些代碼; Y7 \. C; c2 F" a- v8 Q
functions.php中的代碼8 x! j0 V1 k9 I: k% g& g' p9 y" z
/ r# A% f! W0 O5 E* o( @/*-----------------------------------------------------------------------------------*/
) h% Y. q# W9 n5 f/* Load Menu Description
3 D8 B) d0 t) d5 Z/*-----------------------------------------------------------------------------------*/
0 R( o8 h$ V" L, I' Q- j9 Iclass mts_Walker extends Walker_Nav_Menu
( x1 M: u C# _# |' p. j: R6 |{
+ r2 j/ s1 R; Q! y2 A7 ?. E function start_el(&$output, $item, $depth, $args) {: k, M8 K4 [; B6 [) S" l
global $wp_query;
& Q6 e$ Z0 Z" h7 N! D $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';' z; V' d: a1 b8 w6 G3 `% ^; L
4 O" N9 w" Z( S3 k" [
$class_names = $value = ''; f l6 I" t+ p' R% f
9 r7 Y! N; Y( E# f% r' E C
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
* k$ L' i! K% n6 [7 H# V/ v8 T& m E( x# r
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
# K; S; G) H4 [5 v $class_names = ' class="' . esc_attr( $class_names ) . '"';
3 F- _! h% [1 q- E o
' I8 X6 j5 r% z E- a; k $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';+ f2 M: T4 w/ D. N
0 r6 ]/ M b+ h* T1 G6 H$ v $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';) I. V! I, ~1 p. m" y
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
! k1 G6 r' v8 w: Y! s $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';3 f% N9 j6 L2 I+ @
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';: K5 [* o0 X0 j! S+ G0 g
2 }0 M1 g: U! S9 E% |
$item_output = $args->before;
4 a9 s- k$ H3 E9 r. R8 ? \ $item_output .= '<a'. $attributes .'>';" x3 e+ D9 i9 D. E
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
3 a O" r6 ~ x! r( a5 Z9 P- t $item_output .= '<br /><span class="sub">' . $item->description . '</span>';
! v {2 r2 _8 H+ O$ [9 W4 T. [ $item_output .= '</a>';
4 q& o: ^' G) F2 B $item_output .= $args->after;2 x6 L/ f" g" p) ~
; m6 `! w$ M. o! y* D
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
- P! C2 \+ e3 W j& y) l9 Z }
6 Y6 R6 M" h7 X* r}1 {4 r: O$ r! h: W
7 X% H+ Q" ~ }$ L ?" e1 p/*-----------------------------------------------------------------------------------*/, I5 p0 Z' P$ ?; C, E. M* F
T; a# ^& O6 ?5 V) m7 ]' d; U導航菜單代碼:% K& x, ]! x! C$ B1 {
1 E6 a% \; h9 {1 ^' G3 t# I<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>
7 T+ G# P' R# `9 `! H$ M7 I<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>
1 f2 h. r% P: W- b+ s: Q/ r7 x<?php } else { ?>
+ i$ h l8 O( i......
) ?& \/ r5 P8 ?% q: ^為什麼導航菜單輸出的標題還是不帶描述呢?- b2 m0 Y5 J1 ~
% E6 x# O' R' d# b
$ C" ?0 B2 z y; s3 _像下面截圖的這種形式) g% a- `7 i0 G0 O2 S* W
! j: u2 S: ?; q! e+ B1 |. A5 n8 Q% n t6 ?0 \+ m; }. ]9 d+ s
* ?0 n8 W4 u3 o
求高手解答,謝謝!! K% P) |: ]1 u% T
/ a6 p- E$ N- C3 R: \
|