Thinkphp obtains the current position of the topic and article ,. How thinkphp gets the current position of the topic and article. This article describes how thinkphp gets the current position of the topic and article. Share it with you for your reference. Specific Implementation methods include thinkphp's method for obtaining the current position of the topic and article,
This article describes how thinkphp obtains the topic and the current position of the article. Share it with you for your reference. The specific implementation method is as follows:
Today, I improved some details of my blog, including modifying the "current position" on the topic page and article page ". In the past, there were very few columns, and they were done in an endless way (the name of the homepage> topic). now there are more columns, and more secondary columns and third-level columns are coming. this method is obviously not suitable, so I improved it. It is not difficult to use a recursive function.
Shows the test result:
View the source file effect:
The code is as follows:
Home page-> PHP learning-> ecshop secondary development-> Add ecshop to Baidu Map and support perimeter marking
The code is as follows:
// Current location-the first parameter catid is the id of the current topic, the second parameter is the title of the article, and the second parameter is blank when calling the current position of the topic.
$ This-> assign ("now_here", $ this-> now_here ($ catid, $ res ['title']);
// To explain, the catid in the topic table category is the topic id, catname is the topic name, asmenu is the parent id of the topic, and asmenu is 0 when it is a top-level topic.
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 help you with PHP programming.
Example: This article describes how thinkphp gets the topic and the current position of the article. Share it with you for your reference. The specific implementation method is as follows...