问答项目---面包削导航的处理!

Posted 帅到要去报警

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了问答项目---面包削导航的处理!相关的知识,希望对你有一定的参考价值。

首先要根据当前的 id 获取到它所有顶级栏目:

要从顶级栏目到二级栏目,所以要倒序排列下:array_reverse();

/**
 * 传递一个分类ID 返回该分类的所有父级分类
 */
function get_all_parent($array,$id){
    $arr = array();
    foreach($array as $v){
        if($v[\'id\'] == $id){
            $arr[] = $v;
            $arr = array_merge($arr,get_all_parent($array,$v[\'pid\']));
        }
    }
    return $arr;
}

定义标签:(考虑到每次访问这个都要去读这个,会很耗性能,所以做了缓存处理)

<?php
namespace Common\\Tag;
use Think\\Template\\TagLib;
class My extends TagLib{
    // 定义标签
    // 参考文章 : http://www.thinkphp.cn/topic/34758.html
    protected $tags = array(        
        \'location\'=> array(\'attr\'=>\'cid\')
    );
    // location 标签
    public function _location($attr,$content){
        $cid = $attr[\'cid\'];
        $str = <<<str
<?php 
    \\$cid = {$cid};
    if(S(\'location_\'.\\$cid)){
        \\$_location_result = S(\'location_\' . \\$cid);
    }else{
        \\$_location_category = M(\'category\')->select();
        \\$_location_result = array_reverse(get_all_parent(\\$_location_category,\\$cid));
        S(\'location_\'.\\$cid);
    }
    foreach(\\$_location_result as \\$v):
        extract(\\$v);
?>
str;
    $str .= $content;
    $str .= \'<?php endforeach; ?>\';
    return $str;
    }
};

具体使用:

<div id=\'location\'>
    <a href="{:U(\'List/index\')}">全部分类</a>
    <if condition="isset($_GET[\'id\'])">&nbsp;&gt;&nbsp;
        <location cid=\'$_GET["id"]\'>
            <if condition="$id == $_GET[\'id\']">
                {$name}
            <else/>
                <a href="{:U(\'List/index\',array(\'id\'=>$id))}">{$name}</a>&nbsp;&gt;&nbsp;
            </if>
        </location>
    </if>
</div>

 

以上是关于问答项目---面包削导航的处理!的主要内容,如果未能解决你的问题,请参考以下文章

vue项目中手动封装面包屑导航

利用 React 高阶组件实现一个面包屑导航

如果在底部导航栏中选择了其他项目,如何删除 floatingActionButton 替换片段

knpMenuBundle制作面包屑导航 左侧导航 碉堡了

夺命雷公狗---DEDECMS----26dedecms面包屑导航的实现

在选择的底部导航视图项目上重新创建片段