非常小黑 發表於 2013-11-18 03:24 
. h6 z" d( G7 f, f2 x# _' L5 }樓主先去找到模板裡面的category.php+ W9 H; K* ?7 c& B/ G: t% {, X
然後看這段代碼然後你去看header.php,添加(或者修改)這段代碼大概 ...
; q+ w- {9 U7 [* f: ?+ m5 Z, @只有在functions.php裡有- //網站描述3 J* y0 w1 b6 G' r( P, @
- function dtheme_description() {
) v; [7 e* O8 _( {2 j - global $s, $post;% H, D: Z2 ~% g" ~
- $description = ''; ]: Y- @5 i+ J5 }+ d
- $blog_name = get_bloginfo('name');
: u; x& {# T7 i( O: U' b% [. Y9 Y - if ( is_singular() ) {4 f( U- a4 G. ]3 [& U
- if( !empty( $post->post_excerpt ) ) {: {8 ]% o2 q# k& }3 g
- $text = $post->post_excerpt;7 a2 a9 P4 o# z
- } else {8 |3 n+ H. s: X1 o: S
- $text = $post->post_content;
_; d7 l# p5 W+ ~% ?( y - }
7 D& H% T" i* p6 g6 \ - $description = trim( str_replace( array( "\r\n", "\r", "\n", " ", " "), " ", str_replace( """, "'", strip_tags( $text ) ) ) );
: F7 }2 k/ u; a: I& S - if ( !( $description ) ) $description = $blog_name . "-" . trim( wp_title('', false) );! w! U x/ ~8 s* q0 K* E0 v# V
- } elseif ( is_home () ) { $description = $blog_name . "-" . get_bloginfo('description') . dopt('d_description'); // 首頁要自己加
% {* B6 K4 K, c* h# \2 M2 D - } elseif ( is_tag() ) { $description = $blog_name . "'" . single_tag_title('', false) . "'";
C, j9 T+ ^: S& h9 | ] - } elseif ( is_category() ) { $description = single_cat_title('', false) . "'";
; [ W2 D4 s: Y$ l( n5 A. D( c9 l - } elseif ( is_archive() ) { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
4 z5 W5 `4 B: V' _3 b, q - } elseif ( is_search() ) { $description = $blog_name . ": '" . esc_html( $s, 1 ) . "' 的搜索結果";" Y0 R! s& s9 N4 o3 _
- } else { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
% L7 M8 f) e& y - }1 I* O# K, _( \! [4 i
- $description = mb_substr( $description, 0, 220, 'utf-8' ) . '..';
# ~3 d$ r& Q" C4 A - echo "<meta name="description" content="$description" />\n";
5 c" c6 D5 X( I* r - }
複製代碼 / m% o8 L% k: [! y5 i
|