非常小黑 發表於 2013-11-18 03:24 
! @( A9 ^$ I2 C! W% f' \9 ^樓主先去找到模板裡面的category.php
7 s' G; K! v8 T7 r; \, m0 q* R然後看這段代碼然後你去看header.php,添加(或者修改)這段代碼大概 ...
( Y5 }- W1 }9 ~% ]& a只有在functions.php裡有- //網站描述+ h7 O$ U' p. ?8 v; W* H
- function dtheme_description() {/ G1 i. c3 [* H& B8 o7 `
- global $s, $post;
: s( o/ `3 ]7 M: U - $description = '';( Y& f- R. S. N+ q; [8 [; }
- $blog_name = get_bloginfo('name');; j/ s$ e' t2 Z) Z! C# N" g
- if ( is_singular() ) {
! e4 I( o; \4 z" T - if( !empty( $post->post_excerpt ) ) {
" ?9 r" D. C: @ g( u - $text = $post->post_excerpt;9 ]' @& v" b$ }* o V5 L( T7 A
- } else {" }4 l. e- P, E+ Y6 ]
- $text = $post->post_content;& @& d" A7 s1 s( K5 o G
- }
( d* B: |4 @. o) E; B - $description = trim( str_replace( array( "\r\n", "\r", "\n", " ", " "), " ", str_replace( """, "'", strip_tags( $text ) ) ) );1 ` s/ M3 a, a" Y
- if ( !( $description ) ) $description = $blog_name . "-" . trim( wp_title('', false) );4 r" w, r) x! A: R
- } elseif ( is_home () ) { $description = $blog_name . "-" . get_bloginfo('description') . dopt('d_description'); // 首頁要自己加/ k% F4 o7 }$ L( ?% M4 ^! z
- } elseif ( is_tag() ) { $description = $blog_name . "'" . single_tag_title('', false) . "'";( ~0 Y( l& {/ O; @) u8 l, y. Z
- } elseif ( is_category() ) { $description = single_cat_title('', false) . "'";. w& Q" {$ \$ q& [8 Y+ {
- } elseif ( is_archive() ) { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";- }. X: F% @" Y. W7 e7 ^
- } elseif ( is_search() ) { $description = $blog_name . ": '" . esc_html( $s, 1 ) . "' 的搜索結果";& O$ U/ _7 e `
- } else { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";, ?" }* H& I0 ]! |7 w
- }1 `' B. V7 q6 R1 S8 ^3 f3 O3 G
- $description = mb_substr( $description, 0, 220, 'utf-8' ) . '..';
( d6 [3 J4 P9 L `) w& L# y - echo "<meta name="description" content="$description" />\n";
. @! B- H( |1 Z" G7 e( |+ Z( y9 V- _ - }
複製代碼
5 o; ?: M& P- N$ C |