过期域名预定抢注

 找回密碼
 免费注册

求wordpress導航菜單輸出標題顯示描述的方法

[複製鏈接]
發表於 2013-11-6 18:27:38 | 顯示全部樓層 |閱讀模式
求高手幫我分析一些代碼$ 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 QQ截图20131106182530.jpg
) ]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
發表於 2013-11-6 19:27:13 | 顯示全部樓層
$item_output .= '<br /><span class="sub">' . $item->description . '</span>';" k% D5 k- B% K  ?0 M% b
' f& t: A, ]4 x8 Q
這個description?4 U: `% |) d# `
3 {, t' x# d. P6 i- }# V; [
你menu的description 有寫嗎?  編輯menu頁面的右上角有個screen options, description勾上
% r. C3 |2 K+ u( N- `" I' A, h9 W2 P3 C7 E
p.s. 我對主題這塊不是很懂...
3 M+ Q/ B# K# C' F& U
回復 给力 爆菊

使用道具 舉報

 樓主| 發表於 2013-11-6 19:39:24 | 顯示全部樓層
luguokankan 發表於 2013-11-6 19:27 , w# V  P. w; Y1 y9 A
$item_output .= '' . $item->description . '';
$ T4 F/ b! v; r3 q! H6 q7 d- w3 [: y  |! c( ~0 ]
這個description?
( d9 _3 ?; Z$ F$ F! j
果然如你所說,沒勾選圖像描述
8 k$ x$ k1 x! K. z9 Q9 A問題解決了,謝謝!!!- c. C- S: r! S# h" h. j
/ w1 A: \$ G) o# ~; Z. E9 Y
回復 给力 爆菊

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 免费注册

本版積分規則

點基跨境 數位編輯創業論壇

GMT+8, 2025-7-16 04:30

By DZ X3.5

小黑屋

快速回復 返回頂部 返回列表