超详细的ZBlog面包屑导航制作教程

应网友 @贺晋军博客 留言

zblogphp面包屑导航怎么制作的?网上的文章是以前的,求指点,谢谢

关于什么是面包屑导航我想各位童鞋都应该非常的了解了吧,这里我就不再叙述了;先贴两段官方WIKI给的代码看下:

页面判断

{if $type=='index'&&$page=='1'}  /*判断首页*/
{if $type=='category'}  /*判断分类页*/
{if $type=='article'}  /*判断日志页,不含独立页面,{if $article.Type==ZC_POST_TYPE_ARTICLE}(另一方案)*/
{if $type=='page'}  /*判断独立页面*/
{if $type=='author'}  /*判断用户页*/
{if $type=='date'}  /*判断日期页*/
{if $type=='tag'}  /*判断标签页*/

分类目录面包屑的代码编写

{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}

上面这两段代码是官方wiki给出的,我们只要结合下以上的代码稍做修改就可以了,下面我们来看下烽烟博客模板使用的面包屑导航代码:

超详细的ZBlog面包屑导航制作教程

{if $type == 'index'}
	<i class="fa fa-bullhorn"></i>网站改版调试中!
{elseif $type == 'category'}
	<i class="fa fa-home"></i> <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"}	
	 <i class="fa fa-home"></i> <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"}
	 <i class="fa fa-home"></i> <a href="{$host}" title="{$name}">首页</a>
	 &raquo; 正文 
{elseif $type =="tag"}
	 <i class="fa fa-home"></i> <a href="{$host}" title="{$name}">首页</a>
	 &raquo;
	 <span class="current">标签存档:{$tag.Name}</span>
{elseif $type =="author"}
	  <i class="fa fa-home"></i> <a href="{$host}" title="{$name}">首页</a>
	  &raquo;
	 <span class="current">{$author.Name} 的文章</span>
{/if}

将上面的代码添加到你想要显示的地方就行了,不过一般都在导航栏下方,效果可以参考烽烟博客

最后编辑于:2016/04/20作者: 烽烟无限