These two months have been written less, not lazy, because too busy-for customers to make the site. Because the customer specifies to use Phpcms v9, but also requires the use of Phpcms v9_42 version to implement the tag pseudo-static, when the Phpcms v9_42 is the latest version, and now Phpcms officially released Phpcms v9_5.x. For the implementation of the PHPCMS V9 implementation of the tag pseudo-static, Baidu will be a lot of, but it is phpcms v9_2x version, and the final result is: domain name/keyword _6_1.html, I see all feel awkward-I will cut the tail of the URL shorter.
Phpcms v9_42 version is currently (2013-10-29) the latest version, compared to the code of the Phpcms v9_2x tag module, the change is larger, so, the Phpcms v9_2x version of Baidu, the implementation method of the tag pseudo-static is out. What do we do? Below I will build the station process in the Phpcms v9_42 version of the tag pseudo-static implementation method, is absolutely the latest (2013.12.10).
Tag module pseudo-Static setting
1. Add URL Rules
Add a new rule to the comment module in the extensions->url rule, in the background, as follows:
{$tag}_{$page}.html
Remember the previous ID number, such as 32, when you are done adding.
2. Write URL rules in code
Opens the phpcms/modules/content/tag.php file and found:
1 |
$infos = $keyword_data_db ->listinfo( $where , ‘`id` DESC‘ , $page , $pagesize ); |
This line adds the following code to the top:
1 |
$urlrules = getcache( ‘urlrules‘ , ‘commons‘ ); |
2 |
$urlrule = $urlrules [32]; //调用url规则 |
And then put
1 |
$infos = $keyword_data_db ->listinfo( $where , ‘`id` DESC‘ , $page , $pagesize ); |
Change into
1 |
$infos = $keyword_data_db ->listinfo( $where , ‘`id` DESC‘ , $page , $pagesize , ‘‘ , ‘9‘ , $urlrule ,Array( ‘tag‘ =>urlencode( $tag ))); |
The goal is to add the previously set URL rules to the query statement.
3. Modify the template
Open phpcms\templates\default\content\show.html, find:
1 |
{APP_PATH}index.php?m=content&c=tag&a=lists&tag={urlencode( $keyword )} |
Change into
{App_path} {UrlEncode ($keyword)}_1.html
Turn on the phpcms\templates\default\content\tag.html and put the Paging tab
Change into
1 |
{ str_replace ( "_0.html" , "_1.html" , $pages )} |
4. Add a URL rule to the. htaccess file
In the root directory of the Web site. htaccess file (not built by yourself) add the following URL rules
1 |
RewriteRule ^(.*)_([0-9]+).html index.php?m=content&c=tag&a=lists&tag= $1 &page= $2 |
The last URL style shown is as follows: http:/w3note.com/keyword _1.html
Problems that you may encounter
On the operating system: Linux, when you click on the label, there is a hint that the keyword could not be found because of the transcoding problem, which is not the case for local testing.
The solution
Open phpcms/modules/content/tag.php
Found it
1 |
$tag = safe_replace( addslashes ( $_GET [ ‘tag‘ ])); |
Add the following code below it
1 |
$tag = iconv( "gb2312" , "utf-8" , $tag ); //转编码 |
If not, do not try to replace the "gb2312", "utf-8" position.
Reprint: w3note.com/web/133.html