久青草国产观看在线视频,在线观看欧美日女,777毛片,亚洲国产精品99久久久久久久

代碼實(shí)現(xiàn)WordPress自動關(guān)鍵詞keywords與描述description

2015-08-03 wordpress教程
  • 文章介紹
  • 快速入門
  • 評價&建議

以下代碼實(shí)現(xiàn)的是以標(biāo)簽為關(guān)鍵詞;以摘要為描述,如果沒有填寫摘要,那就自動截取文章前200字為描述。(教程轉(zhuǎn)自:DeveWork)

代碼實(shí)現(xiàn)WordPress自動關(guān)鍵詞與描述:

以下代碼放到你的主題下funtions.php的最后一個 ?>前:

  1. //自動關(guān)鍵詞與描述?
  2. function?get_cats_name()?{
  3. $allcats=get_categories();
  4. foreach?($allcats?as?$category)
  5. {
  6. $keywords[]?=?$category->cat_name;
  7. }
  8. return?$keywords;
  9. }
  10. //?utf8?substr
  11. function?utf8Substr($str,?$from,?$len)?{
  12. return?preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'.
  13. '((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s',
  14. '$1',$str);
  15. }
  16. //?Meta?SEO
  17. function?meta_SEO()?{
  18. global?$post;
  19. $output?=?'';
  20. if?(is_single()){//如果是文章頁
  21. $keywords?=?'';
  22. $description?=?'';
  23. if?($post->post_excerpt)?{//如果文章摘要存在就以文章摘要為描述
  24. $description?=?$post->post_excerpt;
  25. $description?=?str_replace("rn","",$description);
  26. $description?=?str_replace("n","",$description);
  27. $description?=?str_replace(""","'",$description);
  28. $description?.=?'...';
  29. }?else?{//如果文章摘要不存在就截斷文章前200字為描述
  30. $description?=?utf8Substr(strip_tags($post->post_content),0,200);
  31. $description?=?str_replace("rn","",$description);
  32. $description?=?str_replace("n","",$description);
  33. $description?=?str_replace(""","'",$description);
  34. $description?.=?'...';
  35. }
  36. $tags?=?wp_get_post_tags($post->ID);//取文章標(biāo)簽
  37. foreach?($tags?as?$tag?)?{
  38. $keywordarray[]?=?$tag->name;
  39. }
  40. //以文章標(biāo)簽為關(guān)鍵字
  41. $keywords?=?implode(',',array_unique((array)$keywordarray));
  42. }?else?{//如果不是文章頁
  43. $keywords?=?'wordpress,wordpress主題,wordpress教程,wordpress主題下載,wordpress博客主題,wordpress企業(yè)主題,wordpress主題定制';?//在引號間寫入你博客的關(guān)鍵字用,斷開
  44. $description?=?'主題貓,致力于為廣大網(wǎng)友提供最新最全的wordpress主題';//在引號間寫入你博客的簡單描述,不要過200字
  45. }
  46. //輸出關(guān)鍵字
  47. $output?.=?'<meta?name="keywords"?content="'?.?$keywords?.?'"?/>'?.?"n";
  48. $output?.=?'<meta?name="description"?content="'?.?$description?.?'"?/>'?.?"n";
  49. //輸出描述
  50. echo?"$outputn";
  51. }
  52. add_action('wp_head',?'meta_SEO');//添加meta_SEO函數(shù)到頭部信息里

第43行與第44行的內(nèi)容需要根據(jù)你的網(wǎng)站進(jìn)行修改。

1 0

企業(yè)建站推薦正版商業(yè)主題,國內(nèi)專業(yè)團(tuán)隊(duì)開發(fā),完善售后,是您不二選擇。

正版主題商店

主題貓WP建站,累計幫助1300+客戶成功建站,為站長提供支持!

立刻開啟你的建站之旅
QQ在線客服

服務(wù)熱線

wordpress建站咨詢