小弟在開發時遇到個問題,思路大概是這樣的:
$notcat, 'post__not_in' => $sticky, 'post_type'=>array( 'post','detail','jingyan','haitao'), 'posts_per_page' => 15, 'paged' => $paged ); query_posts( $args );?>...
set('post_type',$post_type); $query->set('posts_per_page', 15); return $query; }}
問題來了: 按照這樣的方法輸出內容後,分頁僅按照文章數顯示。例如,「Post」下有 60 篇文章,「detail」、「jingyan」、「haitao」各 10 篇。按照想法應分 (60+10*3)/15 = 6 頁。然而實際情況為翻至 60/15 = 4 頁結束後,第 5、6 頁均顯示 404.
Copy 別人的 pagenavi()
:
request; $posts_per_page = intval(get_query_var('posts_per_page')); $paged = intval(get_query_var('paged')); $numposts = $wp_query->found_posts; $max_page = $wp_query->max_num_pages; if(empty($paged) || $paged == 0){ $paged = 1; } $pages_to_show = intval($pagenavi_options['num_pages']); $pages_to_show = intval(4); $pages_to_show_minus_1 = $pages_to_show-1; $half_page_start = floor($pages_to_show_minus_1/2); $half_page_end = ceil($pages_to_show_minus_1/2); $start_page = $paged - $half_page_start; if($start_page <= 0) { $start_page = 1; } $end_page = $paged + $half_page_end; if(($end_page - $start_page) != $pages_to_show_minus_1) { $end_page = $start_page + $pages_to_show_minus_1; } if($end_page > $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if($start_page <= 0) { $start_page = 1; } if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) { $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), "共 %TOTAL_PAGES% 頁"); $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text); echo $before.''."\n"; if(!empty($pages_text)) { echo ''.$pages_text.''; } if ($start_page >= 2 && $pages_to_show < $max_page) { $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), "« 第一頁"); echo ''.$first_page_text.''; echo '...'; } previous_posts_link("«"); for($i = $start_page; $i <= $end_page; $i++) { if($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), "%PAGE_NUMBER%"); echo ''.$current_page_text.''; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), "%PAGE_NUMBER%"); echo ''.$page_text.''; } } next_posts_link("»", $max_page); if ($end_page < $max_page) { echo ''."...".''; $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), "最後 »"); echo '最後 »'; } echo ''.$after."\n"; } }} ?>
回複內容:
小弟在開發時遇到個問題,思路大概是這樣的:
$notcat, 'post__not_in' => $sticky, 'post_type'=>array( 'post','detail','jingyan','haitao'), 'posts_per_page' => 15, 'paged' => $paged ); query_posts( $args );?>...
set('post_type',$post_type); $query->set('posts_per_page', 15); return $query; }}
問題來了: 按照這樣的方法輸出內容後,分頁僅按照文章數顯示。例如,「Post」下有 60 篇文章,「detail」、「jingyan」、「haitao」各 10 篇。按照想法應分 (60+10*3)/15 = 6 頁。然而實際情況為翻至 60/15 = 4 頁結束後,第 5、6 頁均顯示 404.
Copy 別人的 pagenavi()
:
request; $posts_per_page = intval(get_query_var('posts_per_page')); $paged = intval(get_query_var('paged')); $numposts = $wp_query->found_posts; $max_page = $wp_query->max_num_pages; if(empty($paged) || $paged == 0){ $paged = 1; } $pages_to_show = intval($pagenavi_options['num_pages']); $pages_to_show = intval(4); $pages_to_show_minus_1 = $pages_to_show-1; $half_page_start = floor($pages_to_show_minus_1/2); $half_page_end = ceil($pages_to_show_minus_1/2); $start_page = $paged - $half_page_start; if($start_page <= 0) { $start_page = 1; } $end_page = $paged + $half_page_end; if(($end_page - $start_page) != $pages_to_show_minus_1) { $end_page = $start_page + $pages_to_show_minus_1; } if($end_page > $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if($start_page <= 0) { $start_page = 1; } if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) { $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), "共 %TOTAL_PAGES% 頁"); $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text); echo $before.''."\n"; if(!empty($pages_text)) { echo ''.$pages_text.''; } if ($start_page >= 2 && $pages_to_show < $max_page) { $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), "« 第一頁"); echo ''.$first_page_text.''; echo '...'; } previous_posts_link("«"); for($i = $start_page; $i <= $end_page; $i++) { if($i == $paged) { $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), "%PAGE_NUMBER%"); echo ''.$current_page_text.''; } else { $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), "%PAGE_NUMBER%"); echo ''.$page_text.''; } } next_posts_link("»", $max_page); if ($end_page < $max_page) { echo ''."...".''; $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), "最後 »"); echo '最後 »'; } echo ''.$after."\n"; } }} ?>