我的页面上存在分页问题。 我使用插件WP-Paginate。它在index.php上工作正常,但在category.php中不起作用。当我想转到下一页时,它将我重定向到index.php,没有帖子???
这是我的category.php代码:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 10,
'paged' => $paged
);
$cat_query = new WP_Query( $args ); ?>
<?php if ($cat_query->have_posts()) : ?>
<?php while ($cat_query->have_posts()) : $cat_query->the_post(); ?>
POST TEMPLATE
<?php endwhile; ?>
<?php else : ?>
//
<?php endif; ?>
<?php wp_paginate(); ?>
希望我们能修复它
问候!
答案 0 :(得分:0)
您可以使用以下功能创建自定义分页。将此代码放在functions.php文件中
function pagination($pages = '', $range = 1){
$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 "<div class=\"pagination\"><span class='page-number'>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a class='first' href='".get_pagenum_link(1)."'>« First </a>";
if($paged > 1 && $showitems < $pages) echo "<a class='preview' href='".get_pagenum_link($paged - 1)."'>‹ </a>";
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a class='next' href=\"".get_pagenum_link($paged + 1)."\">›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a class='last' href='".get_pagenum_link($pages)."'>Last »</a>";
echo "</div>\n";
}
}
输入此代码后,只需在要显示分页的位置调用该函数。
if (function_exists("pagination")) {
pagination($query->max_num_pages); //replace $query to $cat_query
}