昨晚写完文章突然发现点击tags竟然无法定位到相应的文章,出现的竟然是没找到相关页面的界面。上网一顿搜索,终于找到原因,原来还是WP对中文字符码之间转换的问题,后来在Cool Blog找到了解决的方法,现在拿出来共享一下。

在WordPress中中文Tag被定义为ASCII码,所以当搜索或者是通过Tag访问文章时会出现ASCII乱码路径的现象,在此给大家分享一下我的办法:


1.首先找到/wp-includes/rewrite.php 文件(在操作前请将其备份,以免修改出错。);
2.打开 rewrite.php 文件找到一下代码:
function get_tag_permastruct() {
if (isset($this->tag_structure)) {
return $this->tag_structure;
}
if (empty($this->permalink_structure)) {
$this->tag_structure = ”;
return false;
}
if (empty($this->tag_base))
$this->tag_structure = $this->front . ‘tag/’;
else
$this->tag_structure = $this->tag_base . ‘/’;
$this->tag_structure .= ‘%tag%’;
return $this->tag_structure;

3.注意那行蓝色的代码,将其修改为:
if (! empty($this->permalink_structure)) {
就是在empty…前添加上一个英文的叹号”!”就是了。
4.保存!完工当然就要保存我们的劳动果实了,呵呵。

试一下吧,很好的哦。呵呵

这次遇到这个现象的时候,我到网上查了一下,还有种方法,在此也告诉大家一下,但效果如何并不清楚:

如何让WordPress的tag支持中文

今天,研究了一下午,终于找到WordPress自带的tag在IIS上不能支持中文的原因了,是因为IIS对中文url解析的问题,修改的方法很简单:

打开wp-includes\classes.php文件,找到第44行:

44
45
46
47
48
49
50
if ( isset($_SERVER[‘PATH_INFO’]) )
$pathinfo = $_SERVER[‘PATH_INFO’];
else

$pathinfo = ;

$pathinfo_array = explode(‘?’, $pathinfo);
$pathinfo = str_replace(“%”, “%25″, $pathinfo_array[0]);
$req_uri = $_SERVER[‘REQUEST_URI’];

把它改成这样:

44
45
46
47
48
49
50
if ( isset($_SERVER[‘PATH_INFO’]) )
$pathinfo = mb_convert_encoding($_SERVER[‘PATH_INFO’], “UTF-8″, “GBK”);
else
$pathinfo = ;
$pathinfo_array = explode(‘?’, $pathinfo);
$pathinfo = str_replace(“%”, “%25″, $pathinfo_array[0]);
$req_uri = mb_convert_encoding($_SERVER[‘REQUEST_URI’], “UTF-8″, “GBK”);

, ,

17fav 收藏本文

相关日志

引用地址:http://www.skyow.com/blog/index.php/click-on-tags-can-not-be-found-to-solve-the-problem-of-the-article.htm



发表评论

(必填)
(必填,不公开)

收藏 & 分享

Powered by 17fav.com