February 22, 2009
解决 WordPress 分页插件 Paginator 缺斜杠、双斜杠问题
Paginator 分页插件让用惯了 PageNavi 的 WordPress 用户耳目一新,但是安装后发现分页链接格式有点小问题,可能会缺少必要的斜杠或多出一个斜杠,导致 http://hellobmw.com/page/2 错误地变成 http://hellobmw.com/page2 或者 http://hellobmw.com/page//2。
据我推测,出现这种情况的 WordPress 可能设置了自定义 Permalink,并且 Permalink 格式最后没有斜杠(如:http://hellobmw.com/archives/xxx.html),另外问题主要集中在 category 和 tag 链接上(index 页没出问题是 WordPress 自动加上了"/")。
废话不说了,解决办法也很简单,那就是让插件视情况加减斜杠而不是一刀切,插件原本的代码忘了,只贴我改过的那一部分吧,大家仔细看两段代码细小的差别:
Thanks very much for Lilumi's great work to fix all the bugs of Paginator 3000.
非常感谢乌克兰的 Lilumi 对 Paginator 3000 斜杠 bug 的完美修正!我原来修正方法也是存在 bug 的,已经删掉了。下面是他的修改方法,在
中找到
在这行前面插入
这样修改的目的是把所有链接进行统一,都把最后的斜杠去掉(如果有的话),然后再利用下面的代码统一只加一次斜杠:
'<script type="text/javascript">
if(navigator.appName=="Microsoft Internet Explorer"){
var prevonload=window.onload;
if(typeof window.onload!="function"){
window.onload=function(){
pag = new Paginator("paginator",' . $wp_query->max_num_pages . ',' . $pages_to_show . ',' . $paged . ',"' . clean_url(get_pagenum_link_without_queries()).'/page/","'.get_pagenum_link_query().'");
}
}else{
window.onload=function(){
prevonload();
pag = new Paginator("paginator",' . $wp_query->max_num_pages . ',' . $pages_to_show . ',' . $paged . ',"' . clean_url(get_pagenum_link_without_queries()).'/page/","'.get_pagenum_link_query().'");
}
}
}else{
pag = new Paginator("paginator",' . $wp_query->max_num_pages . ',' . $pages_to_show . ',' . $paged . ',"' . clean_url(get_pagenum_link_without_queries()).'/page/","'.get_pagenum_link_query().'");
}
</script>');
经过测试,这样就可以达到完美的效果啦!Now, Paginator is perfect!

真奇怪,怎么插件的作者没有来感谢你呢?
@hhalloyy 从今天开始做正事,不想折腾了。
受您感召,也用上這個插件了~我的Permalink後面有斜杠,所有沒有這個問題哈哈~
@Leeiio 好,这样便证明了我的推测是正确的。
thank you wery much for fast bug fixing
but this bug now on other pages: http://hellobmw.com/tag/google/page/3
do you now how to fix this?
@lilumi wow, it’s really frustrating that fixing a bug causes new bugs. I have no idea how to make it absolutely right at present but only some tricks…sorry.
Woohoo — I’m fixed all bugs with slashes.
in
function get_pagenum_link_without_queries()before:
$result = apply_filters('get_pagenum_link', $result);insert this:
if ($result[strlen($result)-1]=="/") $result = substr($result,0,strlen($result)-1);Woohoo — I’m fixed all bugs with slashes.
in
function get_pagenum_link_without_queries()before:
$result = apply_filters('get_pagenum_link', $result);insert this:
if ($result[strlen($result)-1]=="/") $result = substr($result,0,strlen($result)-1);p.s. why your antispam system marking my comments as a spam???
@lilumi Yeah, you’re great! I have tested your method on my blog and it works perfectly! Thank you lilumi!
@lilumi Your comments were all approved without any problems.
your antispam system don’t approve my comments when i fill the “site url”
@lilumi Is it true? Let me see what happened.
@lilumi
I’m so sorry. My primary anti-spam plugin Spam Karma 2 put “org.ua” in its domain blacklist by mistake so that all comments whose urls end with “org.ua” were killed. Now I have put “org.ua” in the whiltelist, everything will be right.
Thanks for both of you guys for your contribution.
I will address the issue in the next update.
It will come out some time today or tomorrow.
Sorry for inconvenience.
@dzhus You’re welcome. I really love your Paginator 3000.
末尾斜杠WP貌似提供专门函数处理的- -。trailingslashit($str)在URL末尾加/ 。untrailingslashit去除/。还有user_trailingslashit根据用户设置的permalink末尾有没有/ 对URL处理。这几个函数都会判断URL末尾是否已有/,有的话不会重复添加。
@小野大神 谢谢!
恒顺网.友
http//zhjgxs.lingd.net
经典
你好,站长,关于pagintar,似乎官方下载都是2.6.3的。我是2。7。1的我装后,没有反映,不知道如何解决。希望您能指点下,我php不是很懂。基本就是猜的~~
菜鸟前来观光,感受一下熏陶 干洗