Home>Article>Backend Development> How to implement breadcrumb navigation in php
php method to implement breadcrumb navigation: [public function mbx($cat_id){$goods_info = D('goods')->find( I ('get.goods_id') );$row = D('cat')->f...].
The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.
The role of breadcrumb navigation is to tell visitors where they are on the website and how to return. Many friends may not know much about breadcrumb navigation. In fact, it comes from a fairy tale "Hansel and Gretel". When Hansel and Gretel were walking through the forest, they accidentally got lost, but they found that they were walking along the way. Breadcrumbs were scattered wherever they went to help them find their way home.
There are three types of breadcrumb navigation, namely:
1. Location-based breadcrumb navigation
This type is the most common. This type of breadcrumb navigation is a great way to point out the hierarchy of the current page and the entire site. This breadcrumb navigation can display links to the previous page or directory of the current page. This allows visitors to understand their location and find the page they want to reach more quickly. It can greatly improve the user-friendly experience.
2. Attribute-based breadcrumb navigation
This kind of breadcrumb navigation most often appears on e-commerce sites. This kind of breadcrumb navigation can be a good way to point out other attributes or categories of products on the current page. A product often has more than one attribute, and this breadcrumb navigation can give consumers a more intuitive understanding.
3. Path-based breadcrumb navigation
This kind of breadcrumb navigation is the least common. This type of breadcrumb navigation is very similar to the fairy tale type mentioned above. They can display links to web pages that visitors visited before arriving at the page. Breadcrumbs are not very popular because they basically function the same as forward and back buttons.
So how do we implement breadcrumb navigation? Let’s take a look at the specific implementation code!
The specific implementation code is as follows:
find($cat_id); $tree[] = $row;//将该条数据放入数组中 while($row['parent_id']>0){//只要该条数据的parent_id>0 $row = D('cat_id')->fine($row['parent_id']); $tree[] = $row; } //array_reverse();返回翻转数据的数组 return array_reverse($tree);//翻转数据 } //修改对应的显示到模板中的方法 public function goods(){ //获取该条数据的信息 $goods_info = D('goods')->find( I ('get.goods_id') ); //打印该条信息的面包屑导航 //var_dump($this->mbx($goods_info['cat_id'])); $this->assign('mbx' , $this->mbx($goods_info['cat_id'])); $this->assign('goods' , $goods_info); $this->play(); } //显示到模板中 当前位置 首页{} {$goods['goods_name']} ?> }>
Recommended learning:php training
The above is the detailed content of How to implement breadcrumb navigation in php. For more information, please follow other related articles on the PHP Chinese website!