首先以zblogPHP分类增加自定义标题、关键词、描述功能为例:
1、在include.php的function ActivePlugin_模板id(){中挂载:
Add_Filter_Plugin('Filter_Plugin_Category_Edit_Response','ydmao_cate_seo');//分类自定义字段
2、在function ActivePlugin_模板id(){.....}后加入:
function ydmao_cate_seo(){ global $zbp,$cate; echo '<div id="alias" class="editmod"> <span class="title">当前分类标题、关键词、描述<font color="#FF0000">(不填写则按主题默认显示)</font></span><br /> <strong>标题</strong><br> <input type="text" style="width:75%;" name="meta_ydmao_catetitle" value="'.htmlspecialchars($cate->Metas->ydmao_catetitle).'"/><br> <strong>关键词</strong><br> <input type="text" style="width:75%;" name="meta_ydmao_catekeywords" value="'.htmlspecialchars($cate->Metas->ydmao_catekeywords).'"/><br> <strong>描述</strong><br> <input type="text" style="width:75%;" name="meta_ydmao_catemiaoshu" value="'.htmlspecialchars($cate->Metas->ydmao_catemiaoshu).'"/> </div>'; }
以上两步就可以在zblogPHP模板的分类中加入了三个SEO字段,剩下的就是如何调用出来,而且必须调用出来,不然以上操作都没有任何意义。
所以需要在模板的header.php中的</head>前加入:
{if $type=='category'} <!-- 判断在分类页面时候 --> <title>{if $category->Metas->ydmao_catetitle}{$category.Metas.ydmao_catetitle}{else}{$title}_{$name}{if $page>'1'}_第{$pagebar.PageNow}页{/if}{/if}</title> <meta name="Keywords" content="{if $category->Metas->ydmao_catekeywords}{$category.Metas.ydmao_catekeywords}{else}{$title},{$name}{/if}" /> <meta name="description" content="{if $category->Metas->ydmao_catemiaoshu}{$category.Metas.ydmao_catemiaoshu}{else}{$category.Intro}_{$name}{if $page>'1'}_当前是第{$pagebar.PageNow}页{/if}{/if}" /> {else} 这里是zblog模板原有的标题关键词描述等代码 {/if}
注:代码中的ydmao为模板的应用ID,切记!!!
以上完成后,在编辑任一分类的时候,就会显示:
而zblog模板的tag标签也加入SEO(标题关键词描述)也和这个基本一样,如下:
1、同样是挂载:
Add_Filter_Plugin('Filter_Plugin_Tag_Edit_Response','ydmao_tag_seo');//tag自定义字段
2、之后加入:
//tag SEO function ydmao_tag_seo(){ global $zbp,$tag; echo '<div id="alias" class="editmod"> <span class="title">当前TAG标题、关键词、描述<font color="#FF0000">(不填写则按主题默认显示,注:此功能为当前模板自带)</font></span><br /> <strong>标题</strong><br> <input type="text" style="width:75%;" name="meta_ydmao_tagtitle" value="'.htmlspecialchars($tag->Metas->ydmao_tagtitle).'"/><br> <strong>关键词</strong><br> <input type="text" style="width:75%;" name="meta_ydmao_tagkeywords" value="'.htmlspecialchars($tag->Metas->ydmao_tagkeywords).'"/><br> <strong>描述</strong><br> <input type="text" style="width:75%;" name="meta_ydmao_tagmiaoshu" value="'.htmlspecialchars($tag->Metas->ydmao_tagmiaoshu).'"/> </div>'; }
3、模板中加入:
{if $type=='tag'} <title>{if $tag->Metas->ydmao_tagtitle}{$tag.Metas.ydmao_tagtitle}{if $page>'1'}_第{$pagebar.PageNow}页{/if}{else}{$tag.Name}_{$name}{if $page>'1'}_第{$pagebar.PageNow}页{/if}_{$subname}{/if}</title> <meta name="Keywords" content="{if $tag->Metas->ydmao_tagkeywords}{$tag.Metas.ydmao_tagkeywords}{else}{$tag.Name}{/if}"> {if $tag.Intro || $tag->Metas->ydmao_tagmiaoshu}<meta name="description" content="{if $tag->Metas->ydmao_tagmiaoshu}{$tag.Metas.ydmao_tagmiaoshu}{else}{$tag.Intro}{/if}">{/if} {/if}