非常小黑 發表於 2013-11-18 03:24 4 @: M3 A1 h! u8 ^
樓主先去找到模板裡面的category.php/ i$ p& j- z: ^) I
然後看這段代碼然後你去看header.php,添加(或者修改)這段代碼大概 ... 9 ~: o4 b: \1 F: [
只有在functions.php裡有- //網站描述
6 l7 b: R! U: }8 }/ W6 F - function dtheme_description() {
" f1 Y% s$ x$ f$ R* S$ x% A - global $s, $post;
% j: E4 x0 `. v( K! ~7 O7 w( O - $description = '';/ h3 r. u$ r7 D" V0 Z6 ~& J
- $blog_name = get_bloginfo('name');! `# W; H2 @1 d
- if ( is_singular() ) {: R5 ?- N8 ^1 A" k
- if( !empty( $post->post_excerpt ) ) {
9 g6 Y# n+ [: T- w+ l- p' Q - $text = $post->post_excerpt;
) m0 b3 _. B7 c/ e! ?* q - } else {9 x) k( t6 K% A
- $text = $post->post_content;8 Y3 `% T3 C4 P) G
- }9 K& K" [) k; c& K6 G! q
- $description = trim( str_replace( array( "\r\n", "\r", "\n", " ", " "), " ", str_replace( """, "'", strip_tags( $text ) ) ) );
# F# W8 C* q, X# b8 ^9 S - if ( !( $description ) ) $description = $blog_name . "-" . trim( wp_title('', false) );
0 x1 O+ [0 c2 z a - } elseif ( is_home () ) { $description = $blog_name . "-" . get_bloginfo('description') . dopt('d_description'); // 首頁要自己加' j$ B! }$ t- s* ^6 s, C
- } elseif ( is_tag() ) { $description = $blog_name . "'" . single_tag_title('', false) . "'";% k* `. H1 v- m+ x
- } elseif ( is_category() ) { $description = single_cat_title('', false) . "'"; h7 r* E4 `: [. B6 y
- } elseif ( is_archive() ) { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
, P5 U( y/ V. ]( U2 R0 z! j1 z - } elseif ( is_search() ) { $description = $blog_name . ": '" . esc_html( $s, 1 ) . "' 的搜索結果";& {9 _ \1 e# f/ a! Y
- } else { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";% y# ~* x# p1 u' K/ Z
- }8 @9 ^$ X! y o `
- $description = mb_substr( $description, 0, 220, 'utf-8' ) . '..';( D$ r* f9 q% ^" V4 ]
- echo "<meta name="description" content="$description" />\n";
/ [4 }9 u2 K2 Y9 i7 N4 V2 s2 s) U - }
複製代碼
. _6 ?( l4 ?# m5 W( `1 p) q |