Emlog模板制作之面包屑导航(参考教程)

2016-8-23 / 7 评论 / 9492 阅读

今天看论坛看到此文章的,虽然比较复杂,但还是很有用的,这里写出来供大家参考,这次写出来我也不知道这是不是很全面吧,不过我估计能有的我都给写进去了。



使用方法:

将以下代码放入模板文件module.php中

<?php
$sheli_mbx = "首页";

if( $params[1]=='page' ){
    $sheli_mbx .= htmlspecialchars(urldecode($params[2]));//获取第某页
}

function __breadcrumb_Sort_Cache($id){
    global $CACHE;
    $sort_cache = $CACHE->readCache('sort');
    return $sort_cache[$id]['sortname'];
}

function __breadcrumb_User_Cache($id){
    global $CACHE;
    $user_cache = $CACHE->readCache('user');
    return $user_cache[$id]['name'];
}

function __breadcrumb_Blog_Sort_Cache_Check($blogid){
    global $CACHE; 
    $log_cache_sort = $CACHE->readCache('logsort');
    if(!empty($log_cache_sort[$blogid])){
        return true;
    }else{
        return false;
    }
}

function __breadcrumb_Blog_Sort_Cache($blogid){
    global $CACHE; 
    $log_cache_sort = $CACHE->readCache('logsort');
    if(!empty($log_cache_sort[$blogid])){
        //分类名称:$log_cache_sort[$blogid]['name']
        //分类链接:Url::sort($log_cache_sort[$blogid]['id'])
        return $log_cache_sort[$blogid]['name'];
    }
}

if( $params[1]=='sort' ){//分类
    //分类名称:_cache_breadcrumb_Sort_Cache($sortid)
    //分类链接:$sort_url = Url::sort($sortid);
    $sheli_mbx .= __breadcrumb_Sort_Cache($sortid);
    if( $params[4]=='page' ){
        $sheli_mbx .= htmlspecialchars(urldecode($params[5]));//获取第某页
    }
}elseif($params[1]=='record'){//归档
    $sheli_mbx .= $params[2];
    if( $params[4]=='page' ){
        $sheli_mbx .= htmlspecialchars(urldecode($params[5]));//获取第某页
    }
}elseif( $params[1] == 'author' ){//文章
    //作者名称:_cache_breadcrumb_User_Cache($params[2])
    //作者链接:$author_url = Url::author($params[2]);
    $sheli_mbx .= __breadcrumb_User_Cache($params[2]);
    if( $params[4]=='page' ){
        $sheli_mbx .= htmlspecialchars(urldecode($params[5]));//获取第某页
    }
}elseif( $params[1] == 'tag' ){//标签
    //标签名称:htmlspecialchars(urldecode($params[2]));
    //标签链接:$tag_url = Url::tag($params[2]);
    $sheli_mbx .= htmlspecialchars(urldecode($params[2]));
    if( $params[4]=='page' ){
        $sheli_mbx .= htmlspecialchars(urldecode($params[5]));//获取第某页
    }
}elseif( $params[1] == 'keyword' ){//搜索
    $sheli_mbx .= htmlspecialchars(urldecode($params[2]));
    if( $params[4]=='page' ){
        $sheli_mbx .= htmlspecialchars(urldecode($params[5]));//获取第某页
    }
}elseif( $type=='blog' ){//自定义文章

    //判断文章是否存在分类
    if( __breadcrumb_Blog_Sort_Cache_Check($logid) ){
        $sheli_mbx .= __breadcrumb_Blog_Sort_Cache($logid);
    }

    //文章名称:$log_title
    //文章链接:Url::log($logid);
    $sheli_mbx .= $log_title;
}elseif( $type=='page' ){//自定义文章
    $sheli_mbx .= $log_title;
}elseif( $tws ){

    preg_match_all('|^.*/\?(page)=(\d+)([\?&].*)?$|',Dispatcher::setPath(),$Preferred);
    if( $Preferred[1][0]=='page' ){
        $sheli_mbx .= htmlspecialchars(urldecode($Preferred[2][0]));
    }

    $sheli_mbx .= '微语';
};?>

最后在你需要的位置放入<?php echo $sheli_mbx;?>即可完工,至于CSS什么的,自己折腾吧。

评论一下?

OωO
取消
    1. 头像
      心岛
      板凳
      老大,我调用出来的面包屑为啥没有任何html间隔的,这可咋整?如下所示:
      <div class="text">首页服务中心免责声明        </div>
      回复
      1. 头像
        舍力
        @心岛:css方面自己去弄,不解释。
        回复
      1. 头像
        心岛
        @舍力:关键是我会css,因为每个词是挨着的,所以没办法单独用样式表分割出来啊,还请老大明示!
        回复
      1. 头像
        心岛
        @舍力:这不是样式表可以解决的问题了,几个词之间连个结构代码都没有,你让我咋分割?
        回复
    1. 头像
      求教博主
      沙发
      博主,求教首页去掉面包屑的判断代码。
      不好意思,怕文章评论你没时间回复所以放到留言板了,抱歉哦
      回复
      1. 头像
        舍力
        @求教博主:不是你看到的那个页面就有提示教你怎么判断的么?
        回复
      1. 头像
        舍力
        @舍力:教程链接:http://www.shuyong.net/598.html
        回复