phpcms v9 tags列表页伪静态的实现方法

实现方法:

1、在phpcms v9后台添加url规则,具体步骤如下:

后台->扩展->URL规则管理->添加规则->

URL规则名称:category

模块名称:内容模块

是否生成静态?:否

URL示例:tag-1.html

URL规则:{$tag}.html

注意:添加完后记住此规则的ID,下一步要用到。


2、修改 phpcms/modules/content/tag.php 文件

找到

$infos = $keyword_data_db->listinfo($where, '`id` DESC', $page, $pagesize);

修改为

$urlrules = getcache("urlrules","commons");
$urlrule = $urlrules[33];//调用URL规则,此处URL规则为第一步添加后产生的,将33修改为你的url规则ID即可
$infos = $keyword_data_db->listinfo($where, '`id` DESC',$page, $pagesize,"","9",$urlrule,array("tag"=>urlencode($tag)));


3、修改模板文件tag.html和show.html或有动态tag链接的文件,将其中的动态URL路径为伪静态路径

{APP_PATH}index.php?m=content&c=tag&a=lists&tag={urlencode($keyword)}

修改为

{APP_PATH}tag/{urlencode($keyword)}.html


4、修改 tag_list.html 分页标签

实现效果:

把CMS集中营-1.html替换为CMS集中营.html,因为分页标签默认会将第一页显示为:CMS集中营-1.html,但是我们这个方法中第一页为:CMS集中营.html

实现方法:

将默认的

{$pages}

修改为

{str_replace("-1.html",".html",$pages)}


5、伪静态规则,用Editplus或其他编辑器建立一个文档,并命名为 .htaccess 然后保存的时候保存类型选择All File(*.*)在新建立的 .htaccess 文件中加入如下规则

RewriteRule ^tag/(.*)-([0-9]+).html index.php?m=content&c=tag&a=lists&tag=$1&page=$2
RewriteRule ^tag/(.*).html index.php?m=content&c=tag&a=lists&tag=$1

至此就可以实现了,效果为:

http://www.phpcms.com/index.php?m=content&c=tag&a=lists&tag=www.cmsjzy.cn

对应

http://www.phpcms.com/tag/www.www.phpcms.com.html

http://www.phpcms.com/tag/www.www.phpcms.com-2.html


http://www.phpcms.com/index.php?m=content&c=tag&a=lists&tag=CMS集中营

对应

http://www.phpcms.com/tag/CMS集中营.html

http://www.phpcms.com/tag/CMS集中营-2.html


6、如果修改完成后提示不存在此关键字可以进行下边编码转换试试

修改 phpcms/modules/content/tag.php 文件

$tag = safe_replace(addslashes($_GET['tag']));

下边添加

$tag = iconv("gb2312","utf-8",$tag); //转编码


上一篇:phpcms的关键词tag重写为拼音格式

下一篇:phpcms v9 实现首页,列表页,内容页调用点击量方法