首页 > 技术文章 > thinkcmf获取当前位置1

gaojunshan 2017-01-10 15:53 原文

在方法application文件里面的function.php加上一个函数:

 

function getposition($id){
   $path = M('terms')->where(array('term_id'=>$id))->getField('path'); $str = ''; 
   if(!empty($path)){ 
      $path = explode('-', $path);
      foreach ($path as $key => $value) {
         if($value==0){ 
         $str = $str . '<a href="' . __ROOT__ . '">首页</a><i class="iconfont">&#xe608</i>'; }
         else{
         $name = M('terms')->where(array('term_id'=>$value))->getField('name');
         $str = $str . '<a href="' . __ROOT__ . '">' . $name . '</a><i class="iconfont">&#xe608</i>';
          }
       }
     } 
   return $str;
 }

  在文章页页面加上{:getposition($term_id)}就可以了。

推荐阅读