下列编码完成的是以标识为关键字;以引言为叙述,要是没有填好引言,那么就全自动提取文章内容前200字为叙述。(实例教程转自:DeveWork)
编码完成WordPress全自动关键字与叙述:
下列编码放进你的主题风格下funtions.php的最后一个 ?>前:
- //全自动关键字与叙述
- function get_cats_name() {
- $allcats=get_categories();
- foreach ($allcats as $category)
- {
- $keywords[] = $category->cat_name;
- }
- return $keywords;
- }
- // utf8 substr
- function utf8Substr($str, $from, $len) {
- return preg_replace(‘#^(?:[x00-x7F]|[xC0-xFF][x80-xBF] ){0,’.$from.’}’.
- ‘((?:[x00-x7F]|[xC0-xFF][x80-xBF] ){0,’.$len.’}).*#s’,
- ‘$1‘,$str);
- }
- // Meta SEO
- function meta_SEO() {
- global $post;
- $output = ”;
- if (is_single()){//如果是文章内容页
- $keywords = ”;
- $description = ”;
- if ($post->post_excerpt) {//假如文章内容引言存有就以文章内容引言为叙述
- $description = $post->post_excerpt;
- $description = str_replace(“rn”,“”,$description);
- $description = str_replace(“n”,“”,$description);
- $description = str_replace(“””,“‘”,$description);
- $description .= ‘…’;
- } else {//假如文章内容引言不会有就断开文章内容前200字为叙述
- $description = utf8Substr(strip_tags($post->post_content),0,200);
- $description = str_replace(“rn”,“”,$description);
- $description = str_replace(“n”,“”,$description);
- $description = str_replace(“””,“‘”,$description);
- $description .= ‘…’;
- }
- $tags = wp_get_post_tags($post->ID);//取文章内容标识
- foreach ($tags as $tag ) {
- $keywordarray[] = $tag->name;
- }
- //以文章内容标识为关键词
- $keywords = implode(‘,’,array_unique((array)$keywordarray));
- } else {//要不是文章内容页
- $keywords = ‘wordpress,wordpress主题风格,wordpress教程,wordpress主题下载,wordpressblog主题风格,wordpress公司主题风格,wordpress主题订制’; //在冒号间载入你blog的关键词用,断掉
- $description = ‘主题风格猫,专注于为众多网民给予全新最齐的wordpress主题风格’;//在冒号间载入你blog的简易叙述,不必过200字
- }
- //輸出关键词
- $output .= ‘<meta name=“keywords” content=“‘ . $keywords . ‘” />’ . “n”;
- $output .= ‘<meta name=“description” content=“‘ . $description . ‘” />’ . “n”;
- //輸出叙述
- echo “$outputn”;
- }
- add_action(‘wp_head’, ‘meta_SEO’);//加上meta_SEO函数公式到头顶部信息内容里
第43行与第44行的內容必须依据你的网址开展改动。