zblogphp如何添加网站分类目录面包屑导航效果

给zblogphp网站添加网站分类目录面包屑导航效果,能使网站目录层次更加分明,也利于搜素引擎抓取网页。其添加方法也是很简单。大部分情况下,是在zblogphp主题模板文件中的header.php文件里插入面包屑代码,其次,一般就是在文章内容页single.php模板插入面包屑代码

第一种面包屑导航代码

下面为zblog官方wiki提供的面包屑导航代码:

当前位置:<a href='{$host}'>首页</a>
{php}$html='';function navcate($id){global $html;$cate = new Category;
$cate->LoadInfoByID($id);$html ='>> 
<a href="' .$cate->Url.'" title="查看' .$cate->Name. '中
的全部文章">' .$cate->Name. '</a> '.$html;
if(($cate->ParentID)>0)
{navcate($cate->ParentID);
}}navcate($article->Category->ID);
global $html;echo $html;
{/php}>>正文

以上代码效果是:首页 >>分类名称>>正文

但这个代码只能加在single.php模板中,如果应用在page.页面会把分类名称显示为"未分类";

第二种面包屑导航代码

把下面的代码添加到主题模板的header.php文件:

{if $type == 'index'}
{elseif $type == 'category'} 
<a href="{$host}" title="{$name}">首页</a>
{php}$html='';function navcate($id){global $html;
$cate = new Category;$cate->LoadInfoByID($id);
$html ='&raquo;  <a href="' .$cate->Url.'" title="查看' .$cate->Name. '中的全部文章">' .$cate->Name. '</a> '.$html;
if(($cate->ParentID)>0){navcate($cate->ParentID);}}navcate($category->ID);
global $html;echo $html;
{/php}
{elseif $type =="article"}
<a href="{$host}" title="{$name}">首页</a> 
{php}$html='';function navcate($id){global $html;
$cate = new Category;$cate->LoadInfoByID($id);
$html ='&raquo;  <a href="' .$cate->Url.'" title="查看' .$cate->Name. '中的全部文章">' .$cate->Name. '</a>'.$html;
if(($cate->ParentID)>0)
{navcate($cate->ParentID);}}navcate($article->Category->ID);
global $html;echo $html;   
{/php} &raquo; 正文
{elseif $type =="page"}
<a href="{$host}" title="{$name}">首页</a>&raquo; 正文 
{elseif $type =="tag"}
<a href="{$host}" title="{$name}">首页</a>
&raquo; <spanclass="current">标签存档:{$tag.Name}</span>
{elseif $type =="author"}
<a href="{$host}" title="{$name}">首页</a>
&raquo;<span class="current">{$author.Name} 的文章</span>
{/if}

以上代码主要放在主题模板的header.php文件里面,其次,也可以添加到index.php、single.php等各页面的模板文件中。


相关文章

最新主题