0
自上週以來我一直在試圖解決這個問題,但我無法完成它。這個問題本身聽起來很簡單,我的WordPress分頁工作很好,當它不處理分類時,例如:www.example.com/post_type/2但如果我嘗試使用分類,我不能通過第1頁(www.example.com/taxonomy/term/2)。分頁與自定義帖子類型和分類返回404
Custom Post Type = noticias and Taxonomy = assunto,所以我不認爲這個名字在這裏是一個衝突因素。
$custom_query_args['paged'] = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array('post_type' => 'noticias', 'paged' => $custom_query_args['paged'], 'posts_per_page' => 5);
$loop = new WP_Query($args);
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $loop;
while ($loop->have_posts()) : $loop->the_post();
<!-- Content here -->
endwhile;
wp_reset_postdata();
if (function_exists("pagination")) {
pagination($wp_query->max_num_pages);
}
$wp_query = $temp_query;
,我使用ATM的功能:
function pagination($pages = '', $range = 4) {
$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>Página ".$paged." de ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« Primeira</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Anterior</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 href=\"".get_pagenum_link($paged + 1)."\">Próxima ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Última »</a>";
echo "</div>\n";
}
}