SEO添加关键词和描述
以下方法除首页需要自定义以外,其他页面的关键词和描述均为自动生成。
在主题的header.php页面,找到title标签, 删除,然后换成下面的代码。
{$seotitle="自定义标题"} {$seokey="自定义关键词"} {$seodes="自定义描述"} {if $type=='index'} <title>{$seotitle}</title> <meta name="keywords" content="{$seokey}"> <meta name="description" content="{$seodes}"> {elseif $type=='article'} {php} if($article->Metas->title){ $ztitle=$article->Metas->title; }else{ $ztitle=$title."_".$article->Category->Name."_".$name; } if($article->Metas->key){ $keywords =$article->Metas->key; }else{ $keywords = $article->TagsName; } if($article->Metas->des){ $description=$article->Metas->des; }else{ $description = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),135)).'...'); } {/php} <title>{$ztitle}</title> <meta name="keywords" content="{$keywords}" /> <meta name="description" content="{$description}" /> <meta name="author" content="{$article.Author.StaticName}"> {elseif $type=='category'} {php} if($category->Metas->title){ $ztitle=$category->Metas->title; }else{ $ztitle=$title."_".$category->Name."_".$name; } if($category->Metas->key){ $keywords =$category->Metas->key; }else{ $keywords = $category->Name; } if($category->Metas->des){ $description=$category->Metas->des; }else{ $description = $category->Intro; } {/php} <title>{$ztitle}</title> <meta name="keywords" content="{$keywords}" /> <meta name="description" content="{$description}" /> {elseif $type=='page'} <title>{$title}_{$name}_{$subname}</title> <meta name="keywords" content="{$title},{$name}" /> {php} $description = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),135)).'...'); {/php} <meta name="description" content="{$description}" /> <meta name="author" content="{$article.Author.StaticName}"> {else} <title>{$title}-{$name}</title> <meta name="keywords" content="{$seokey}"> <meta name="description" content="{$seodes}"> {/if}
这里用到了文章和分类自定义TKD的功能,如需要可以添加如下代码,不需要可以无视。
添加接口文件
Add_Filter_Plugin('Filter_Plugin_Edit_Response5','ytecn_ai_rpbd_edit_response'); Add_Filter_Plugin('Filter_Plugin_Category_Edit_Response','ytecn_ai_rpbd_Category_Edit_Response');
添加分类页面设置TKD的函数
function ytecn_ai_rpbd_Category_Edit_Response() { global $zbp,$cate; echo '<style type="text/css"> .ytecn_input_img{width:40%!important;} .ytecn_upimgbutton{ width:120px;} .ytecn_upimg{width:100px;vertical-align: middle;}</style>'; echo '<p align="left" class="uploadimg">SEO标题: <input name="meta_title" id="edtTitle" type="text" class="uplod_img" style="width: 60%;" value="'.$cate->Metas->title.'" /> </p>'; echo '<p align="left" class="uploadimg">SEO关键词: <input name="meta_key" id="edtTitle" type="text" class="uplod_img" style="width: 60%;" value="'.$cate->Metas->key.'" /> </p>'; echo '<p align="left" class="uploadimg">SEO描述: <input name="meta_des" id="edtTitle" type="text" class="uplod_img" style="width: 60%;" value="'.$cate->Metas->des.'" /> </p>'; }
添加文章页面设置TKD的函数
function ytecn_ai_rpbd_edit_response() { global $zbp,$article; echo '<style type="text/css"> .ytecn_input_img{width:40%!important;} .ytecn_upimgbutton{ width:120px;} .ytecn_upimg{width:100px;vertical-align: middle;}</style>'; echo '<p align="left" class="uploadimg">SEO标题: <input name="meta_title" id="edtTitle" type="text" class="uplod_img" style="width: 60%;" value="'.$article->Metas->title.'" /> </p>'; echo '<p align="left" class="uploadimg">SEO关键词: <input name="meta_key" id="edtTitle" type="text" class="uplod_img" style="width: 60%;" value="'.$article->Metas->key.'" /> </p>'; echo '<p align="left" class="uploadimg">SEO描述: <input name="meta_des" id="edtTitle" type="text" class="uplod_img" style="width: 60%;" value="'.$article->Metas->des.'" /> </p>'; }