为Sablog的标签添加伪静态

前段时间从sablog论坛上看到有人发的一个标签伪静态插件,于是就装了,但是不是很完善,于是自己就改了下,很简单,只需要修改以下两个文件:
include/common.php
include/func_rewrite.php

下面就跟我一起来修改吧。首先打开include/common.php大于299行找到

$searcharray = array (   
         "/\<a href\=\"(\.*\/*)\?action\=index&cid\=(\d+)(&page\=(\d+))?\"( class\=\"(.+?)\")?\>/e",   
         "/\<a href\=\"(\.*\/*)\?action\=index&setdate\=(\d+)(&page\=(\d+))?\"( class\=\"(.+?)\")?\>/e",   
         "/\<a href\=\"(\.*\/*)\?action\=show&id\=(\d+)(&page\=(\d+))?(#(\w+))?\"( class\=\"(.+?)\")?\>/e",   
         "/\<a href\=\"(\.*\/*)\?action\=(search|reg|login|archives|comments|tagslist|trackbacks|index|links)(&page\=(\d+))?\"( class\=\"(.+?)\")?\>/e", 

在下面加上:

"/\<a href\=\"(\.*\/*)\?action\=tags&item\=(.+?)(&page\=(\d+))?\"([^\>]*)\>/e",

接着在下面两行找到:

$replacearray = array (   
    "rewrite_category('\\1', '\\2', '\\4', '\\6')",   
    "rewrite_archives('\\1', '\\2', '\\4', '\\6')",   
    "rewrite_show('\\1', '\\2', '\\4', '\\6', '\\8')",   
    "rewrite_page('\\1', '\\2', '\\4', '\\6')", 

下面加上:

"rewrite_tags('\\1', '\\2', '\\4', '\\5')",

该文件修改完毕,下面修改include/func_rewrite.php文件,在最后

?> 

前面加上下面的函数:

//转换标签的连接   
function rewrite_tags($head, $item, $page = 1, $extra = '') {   
    global $options;   
    !$page && $page = 1;   
    return '<a href="'.$head.$item.'-'.$page.'.'.$options['rewrite_ext'].'"'.stripslashes($extra).'>';   
}  

最后在.htaccess文件里加上下面这句:

# 具体标签规则   
RewriteRule ^(.*)-([0-9]+)\.html$ index.php?action=tags&item=$1&page=$2 [L]

这样就大功告成了!

This entry was posted in 学习笔记 and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × 2 =