Home > Backend Development > PHP Tutorial > thinkphp method to get the current position of the column and article, _PHP tutorial

thinkphp method to get the current position of the column and article, _PHP tutorial

WBOY
Release: 2016-07-13 10:15:48
Original
1120 people have browsed it

How to get the current position of columns and articles in thinkphp,

The example in this article describes how thinkphp obtains the current position of columns and articles. Share it with everyone for your reference. The specific implementation method is as follows:

Today I improved some details of the blog, including modifying the "current location" on the column page and article page. In the past, there were only a few columns, so we just used the blind method (Home Page -> Column Name), but now there are more columns, and gradually second-level columns and third-level columns are also coming. This method is obviously not suitable, so we improved it. one time. It's not difficult, just use a recursive function.

The test results are shown below:

View the source file effect:

Copy the code The code is as follows:
Homepage -> PHP Learning -> ecshop -> ecshop secondary development -> ecshop joins Baidu map and supports surrounding markers

Copy code The code is as follows:
//Current position - the first parameter catid is the id of the current column, the second parameter is The title of the article. When calling the current position of the column, the second parameter can be empty.
$this->assign("now_here",$this->now_here($catid,$res['title']));

//Explain that catid in the column table category is the column id, catname is the column name, and asmenu is the id of the column parent. When it is a top-level column, asmenu is 0.

protected function now_here($catid,$ext=''){
$cat = M("Category");
$here = 'Homepage';
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$catid")->find();
if($uplevels['asmenu'] != 0)
$here .= $this->get_up_levels($uplevels['asmenu']);
$here .= ' -> '.$uplevels['catname']."";
if($ext != '') $here .= ' -> '.$ext;
return $here;
}
protected function get_up_levels($id){
$cat = M("Category");
$here = '';
$uplevels = $cat->field("catid,catname,asmenu")->where("catid=$id")->find();
$here .= ' -> '.$uplevels['catname']."";
if($uplevels['asmenu'] != 0){
$here = $this->get_up_levels($uplevels['asmenu']).$here;
}
return $here;
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/902780.htmlTechArticlethinkphp’s method of obtaining the current position of columns and articles. This article illustrates how thinkphp obtains the current position of columns and articles. Share it with everyone for your reference. The specific implementation methods are as follows...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template