过期域名预定抢注

 找回密碼
 免费注册

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

[複製鏈接]
發表於 2013-11-6 18:27:38 | 顯示全部樓層 |閱讀模式
求高手幫我分析一些代碼  u! T) z& s0 d3 j
functions.php中的代碼/ Z8 s( ^, Z# L) S2 ?" e( ^0 M, x

6 }# P) l* x: G; u1 G7 P/*-----------------------------------------------------------------------------------*/
. k1 u5 ^- ~8 N0 A4 [/*        Load Menu Description- o  q# c2 y# C$ z( t$ b2 n
/*-----------------------------------------------------------------------------------*/3 U5 y. Y& Z0 S8 S5 _
class mts_Walker extends Walker_Nav_Menu3 Z- y/ S% p6 V! {6 d1 X* J
{3 K8 [( m! N1 z. R9 z  A
        function start_el(&$output, $item, $depth, $args) {% O7 r3 q5 G7 z5 J5 o. F4 R1 @1 s
                global $wp_query;# `$ W9 d5 E/ p/ m* {- z9 u
                $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
1 i/ t; @+ R+ k* t" E6 D  u0 o9 o7 V+ ^
                $class_names = $value = '';8 `: }  z) o) Q4 e/ O; G& S, }7 l
6 |$ k9 p. A5 t/ M) V/ }
                $classes = empty( $item->classes ) ? array() : (array) $item->classes;
/ N. _. r0 z, `% X6 p7 C% q6 ]
                $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
8 L' q; n. @& R& Z2 m& F* B                $class_names = ' class="' . esc_attr( $class_names ) . '"';, @  N% S# F/ `% g) ]  w; i
% R/ f# p6 U$ w! q6 I; a
                $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';1 f, T7 j. y& y$ i# {

! @. M  _& V% K: Q9 {3 N% W; V                $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
& w/ ~- n2 o# B. R                $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
5 V2 o  Y  E& A5 U, j                $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';6 l1 K4 {0 u) g; Y
                $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
" C! W5 }3 p: J: I/ x3 k: j" W% Z! \0 W1 P2 l
                $item_output = $args->before;
" t( x3 p. g5 `+ H                $item_output .= '<a'. $attributes .'>';9 ]/ h8 _. N+ d, d( t- G2 M
                $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
* l4 o9 ~# u! j. H% z                $item_output .= '<br /><span class="sub">' . $item->description . '</span>';
5 \6 z& j/ K% B% w3 y/ k7 d; B) H! S& C                $item_output .= '</a>';/ F/ u. m) F, L% s" g- b
                $item_output .= $args->after;" @% I# }6 {; Z7 P- W& f! Z

! k; x$ ~) {3 p' C, a5 |$ n! I                $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
" n' s: a# C0 ^; U        }6 R/ C; A/ @8 ~- a$ S1 G7 b8 [- Z
}
/ ~9 I& |4 P/ ?+ q" L
3 B; m( y; z5 d( ^% m4 A8 Z5 Z/*-----------------------------------------------------------------------------------*/; M; e" E6 V* A" B2 l. P0 x( n

5 \; ?, m6 T( j3 f0 B  Y導航菜單代碼:
9 ^. x% s. k8 u8 V  x  g5 B- z& ^2 m7 n% I1 ~6 b
<?php if ( has_nav_menu( 'primary-menu' ) ) { ?>
! U4 _$ d$ R2 V6 Q) y. f+ `% W<?php $walker = new mts_Walker; wp_nav_menu( array( 'theme_location' => 'primary-menu', 'menu_class' => 'menu', 'container' => '', 'walker' => $walker ) ); ?>
0 D% F8 a0 R' `' ]% B1 L! r<?php } else { ?>
- ]: {6 J/ C' |% U) I......+ P  x& H/ n+ X) A4 n& F5 ^
為什麼導航菜單輸出的標題還是不帶描述呢?
! N! o: A; n- F" j$ V- o& Z$ O( p3 a: b, r  C% b" P

8 Y( K8 Z! R4 X: \4 H像下面截圖的這種形式
# h2 X6 |( K+ s8 T. L% k9 n( P6 y* t QQ截图20131106182530.jpg ; Y* Q& v6 \; N$ ?

  i' h  {; b' z$ {, N; u5 L/ Q6 s/ H- i1 C
求高手解答,謝謝!
: \% n9 R) X/ U- U9 l9 M$ [( c8 v6 l; K8 d
發表於 2013-11-6 19:27:13 | 顯示全部樓層
$item_output .= '<br /><span class="sub">' . $item->description . '</span>';
, d7 M* L! A; b, X. A% a0 W5 S& S
8 ^5 s5 Y& b, O& m! j這個description?6 G) c6 d( c/ @1 Q, I  r% }

! p; ~! j) ~- X5 K' e你menu的description 有寫嗎?  編輯menu頁面的右上角有個screen options, description勾上) L2 A4 K; C/ Y6 T: A' {+ Z& T

7 N9 t5 `+ W: u9 I0 D. S0 Bp.s. 我對主題這塊不是很懂... # o8 m" w# E9 Q4 Z7 ?( H$ X
回復 给力 爆菊

使用道具 舉報

 樓主| 發表於 2013-11-6 19:39:24 | 顯示全部樓層
luguokankan 發表於 2013-11-6 19:27 5 k2 ^. G, m0 [/ _) a+ n" _( r. e
$item_output .= '' . $item->description . '';
- b& l8 |! L* l5 \& T  D" T$ k/ U
( D( d( O0 x) {- Y4 l: k8 }這個description?

6 U# w5 U: d/ z* U! W3 A果然如你所說,沒勾選圖像描述
# G. S3 T6 W7 B5 {# V0 t' `' ]問題解決了,謝謝!!!* z. I+ h, a- y, \8 n: Y& h8 M

7 T' t' h3 P, }
回復 给力 爆菊

使用道具 舉報

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

本版積分規則

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

GMT+8, 2025-5-26 08:59

By DZ X3.5

小黑屋

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