非常小黑 發表於 2013-11-18 03:24
) Q" ^. ^0 w6 j' r& X) \. q+ H% G樓主先去找到模板裡面的category.php2 Q k0 ?1 J8 ?. q. U# U8 d
然後看這段代碼然後你去看header.php,添加(或者修改)這段代碼大概 ... $ g! \7 r8 f) M' v l+ w+ c
只有在functions.php裡有- //網站描述
+ l; D) u6 V0 u& H - function dtheme_description() {
9 r |' t0 P5 Y) S: E - global $s, $post;
, C8 N4 k. B" j - $description = '';9 v! t. X8 R! n+ [7 `( m3 ?) Y
- $blog_name = get_bloginfo('name');
/ |# d, S' ~0 s) e% } - if ( is_singular() ) {( c$ ^; X8 U$ f: f9 ~4 {
- if( !empty( $post->post_excerpt ) ) {
p1 |! @6 L8 S7 @ - $text = $post->post_excerpt;
6 e8 d! r- Q4 @% v' D - } else {! o4 S7 H3 y2 d1 `6 X/ ]5 u D
- $text = $post->post_content;* Z( o! @. _) t
- }
) Y/ U7 ]2 H A5 y. e - $description = trim( str_replace( array( "\r\n", "\r", "\n", " ", " "), " ", str_replace( """, "'", strip_tags( $text ) ) ) );' F6 c( `2 k5 N% F
- if ( !( $description ) ) $description = $blog_name . "-" . trim( wp_title('', false) );
( X! S" p$ g2 ]! K - } elseif ( is_home () ) { $description = $blog_name . "-" . get_bloginfo('description') . dopt('d_description'); // 首頁要自己加
* {1 E. w" x0 \( P - } elseif ( is_tag() ) { $description = $blog_name . "'" . single_tag_title('', false) . "'";' ]$ U/ R. L/ j3 A4 z& I0 e
- } elseif ( is_category() ) { $description = single_cat_title('', false) . "'";
8 @ \- j& C( x/ S/ r F, j - } elseif ( is_archive() ) { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
; @% J2 ~( a8 U; z+ H - } elseif ( is_search() ) { $description = $blog_name . ": '" . esc_html( $s, 1 ) . "' 的搜索結果";
! E8 S, _9 c, U, u! Y - } else { $description = $blog_name . "'" . trim( wp_title('', false) ) . "'";
' J* P3 ]) A+ |) R4 v - }$ _6 @( X1 R: I" S$ P' k5 _" e
- $description = mb_substr( $description, 0, 220, 'utf-8' ) . '..';; R+ c/ i0 ?5 ^
- echo "<meta name="description" content="$description" />\n";
6 s9 _ ^* {; ~3 @8 p, _3 D - }
複製代碼 & Z" s1 G" Q! i2 @+ j% |
|