过期域名预定抢注

 找回密碼
 免费注册

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

[複製鏈接]
發表於 2013-11-6 18:27:38 | 顯示全部樓層 |閱讀模式
求高手幫我分析一些代碼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 QQ截图20131106182530.jpg   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 \
發表於 2013-11-6 19:27:13 | 顯示全部樓層
$item_output .= '<br /><span class="sub">' . $item->description . '</span>';- o0 x! l" w- z, d; {

" z* M& f2 w; E- P1 u& ]" G這個description?, s9 s6 b3 r( s* D: d( G
0 p6 X9 f3 [* |' U4 i
你menu的description 有寫嗎?  編輯menu頁面的右上角有個screen options, description勾上% M. D: u2 h& U8 \1 j* g' e8 J8 L
  I% Y% ]# _% T6 o" V+ @
p.s. 我對主題這塊不是很懂... ) X1 H% L, R/ Q# I0 x! W9 P; x
回復 给力 爆菊

使用道具 舉報

 樓主| 發表於 2013-11-6 19:39:24 | 顯示全部樓層
luguokankan 發表於 2013-11-6 19:27
/ {  l( n( d7 o5 r: R6 z3 x$item_output .= '' . $item->description . '';) S$ J% ]9 N$ [

2 W- u! {4 b- c! {* L. x( \. ~這個description?

+ O0 [: {" T6 [. Z果然如你所說,沒勾選圖像描述
& e- e  Q* G' _/ h! a問題解決了,謝謝!!!
& }  S/ m! o/ x' @* i* M
, u' t( r: A" p! v
回復 给力 爆菊

使用道具 舉報

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

本版積分規則

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

GMT+8, 2025-5-26 05:50

By DZ X3.5

小黑屋

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