OneThink category-based navigation breadcrumb code
Aug 31, 2016 am 08:41 AMI wanted to add a classified breadcrumb path to the project, but the oneThink frontend didn't seem to provide such a function, so I wrote one myself. I hope it will be useful to everyone.
When we build a website, we often use breadcrumb navigation. Generally, this kind of navigation is based on multi-level classification, and then pushed up level by level. In oneThink, whether it is a list page or an article page, The variable of the current category $category is defined. Therefore, we can use the id in this variable to generate the current path by using the function call of the front-end module.
Without further ado, let’s first create a function in the function of the HOME module, get_category_info();, which is used to find the content of the specified field of the category. It is intended to query the pid and allow_publish fields/**Find the content of the specified field in the specified category<br>
* @param $id<br>
* @param string $field<br>
* @return mixed|string<br>
?*/<br>
function get_category_info($id,$field=""){<br>
<br>
If(!$field){<br>
??????????? return 'No search field specified';<br>
}else{<br>
???????? $map = array(<br>
????????????? 'id'=>array('eq',$id),<br>
???????????? 'status'=>array('eq',1)<br>
);<br>
????????? $re = M('category')->where($map)->getField($field);<br>
Return $ Re; <br>
}<br>
}
Then create the get_bread() function/**<br>
* Get breadcrumbs <br>
* Generate classified breadcrumbs based on classification<br>
* @param $id Current category ID<br>
?*/<br>
function get_bread($id){<br>
//Query pid<br>
$pid = get_category_info($id,'pid');<br>
//Determine whether to use the index template or the lists template based on whether the current category allows publishing content<br>
$temp = get_category_info($id,'allow_publish')?'lists':'index';<br>
??<br>
$str = $pid?<br>
???????????????? get_bread($pid):<br>
'<a href="'.U('Home/Index/index'). '" alt="Home" >Home</a>';<br>
<br>
$str .= ' > <a href="'.U('Home/Article/'.$temp,array('category'=>$id)).'" alt="'.get_category_title($ id).'">'.get_category_title($id).'</a>';<br>
<br>
Return $str;<br>
}
Finally, the front-end tag calls the function get_bread(){:get_bread($category['id'])}

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

The classification of artificial intelligence includes cognitive AI, machine learning AI and deep learning. Artificial intelligence is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence.

When it comes to classifying large amounts of data, manually processing this data is a very time-consuming and difficult task. In this case, using a neural network for classification can do the job quickly and easily. Python is a good choice because it has many mature and easy-to-use neural network libraries. This article will introduce how to use neural networks for classification in Python. Neural Networks and Classification Before explaining how to use neural networks for classification, we need to briefly understand the concept of neural networks. Neural network is a

Python is a widely used programming language that is very popular in computer vision and image processing. In this article, we will explore image classification examples in Python. Image classification is a fundamental task in computer vision that involves identifying objects or scenes in images. This article will introduce how to use the deep learning framework Keras in Python to implement the training and prediction of image classification models. Preparation Before proceeding with image classification, we need to install the necessary software packages. Below is a list of necessary packages

Linux system log files are important files that record various information generated during system operation. By analyzing log files, we can help us understand the operating status, troubleshooting, and performance optimization of the system. This article will deeply explore the classification and functions of Linux system log files, and combine it with specific code examples to help readers better understand. 1. Classification of Linux system log files 1. System log System log is a log file that records important events such as system startup, shutdown, user login, and shutdown. In Linux system

Title: Basic Data Types Revealed: Understand the Classifications in Mainstream Programming Languages ??Text: In various programming languages, data types are a very important concept, which defines the different types of data that can be used in programs. For programmers, understanding the basic data types in mainstream programming languages ??is the first step in building a solid programming foundation. Currently, most major programming languages ??support some basic data types, which may vary between languages, but the main concepts are similar. These basic data types are usually divided into several categories, including integers

This article will introduce the basic concepts and implementation methods of using Gaussian mixture models for classification in Python. What is a Gaussian mixture model? Gaussian Mixture Model (GMM) is a common clustering model, which is composed of multiple Gaussian distributions. When classifying data, these Gaussian distributions are used to model the data and determine each distribution in an adaptive manner. The category to which the sample belongs. The basic principle of GMM The basic principle of GMM is to treat the data set as a group of multiple Gaussian distributions

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a
