WP-PageNavi 2.10 插件的BUG修正

这两天突然发现在搜索页和 tag 搜索页上的 pagenavi 不显示,
于是从网上搜到这个,我稍微修改了一下:
修改 pagenavi.php 内的 wp_pagenavi 函数

function wp_pagenavi($before='', $after='', $prelabel='«', $nxtlabel='»') {
global $request, $posts_per_page, $wpdb, $paged;
if (!is_single()) {
if (get_query_var('post_type') == 'post') {
preg_match('#FROM (.*)\s+(GROUP|ORDER) BY#', $request, $matches);
$fromwhere = $matches[1];//var_dump($request);
if(preg_match('#(.*)\s+(GROUP|ORDER) BY#',$fromwhere,$m2)) {
$fromwhere = $m2[1];
}
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
}
else {
$max_page = 999999;
}
if(empty($paged)) {
$paged = 1;
}

if($max_page > 1) {
echo "$before 页数 ($max_page): <strong>";
if ($paged >= 4) {
echo '<a href="'.get_pagenum_link().'">&laquo; 首页</a> ... ';
}
previous_posts_link($prelabel);
for($i = $paged - 2; $i  <= $paged + 2; $i++) {
if ($i >= 1 && $i <= $max_page) {
if($i == $paged) {
echo "[$i]";
} else {
echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> ';
}
}
}
next_posts_link($nxtlabel, $max_page);
if (($paged+2) < ($max_page)) {
echo ' ... <a href="'.get_pagenum_link($max_page).'">尾页 &raquo;</a>';
}
echo "</strong>$after";
}
}
}
Tags: pagenavi, plugins, wordpress

相关日志

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

还没有评论。

发表评论

(必填)

(必填)


*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comment moderation is enabled. Your comment may take some time to appear.