【发布时间】:2014-01-25 18:14:49
【问题描述】:
我已经用谷歌搜索了这个问题,我担心不仅我有很多编码员面临这个问题。我在那里应用修复但结果相同。请检查我的分页代码好吗?我有一个静态首页,分页将我重定向到主页 (/)。如果我在 url /page/2 之后手动添加这个也将我重定向到主页。我知道这是一个幼稚的问题,但我无法弄清楚问题所在。
这是函数。
function pagination($pages = '', $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<ul class='pagenavi'>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."'>«</a></li>";
if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>‹</a></li>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<li><a href='".get_pagenum_link($i)."' class='current' >".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></li>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'>›</a></li>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>»</a></li>";
echo "</ul>\n";
}
}
用于生成分页的代码
<?php query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'cat'=> $bcatid, 'posts_per_page' => 9 ) );
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
post content
<?php endwhile; endif; ?>
<?php pagination(); ?>
提前感谢您的宝贵时间。
【问题讨论】:
标签: wordpress pagination