Cache the max number of pages to avoid multiple queries. http://mosquito.wordpress.org/view.php?id=1063

git-svn-id: http://svn.automattic.com/wordpress/trunk@2422 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-03-09 04:15:30 +00:00
parent b6cd1461ec
commit ef3ef052e6
1 changed files with 15 additions and 9 deletions

View File

@ -448,12 +448,16 @@ function next_posts($max_page = 0) { // original by cfactor at cooltux.org
}
function next_posts_link($label='Next Page »', $max_page=0) {
global $paged, $result, $request, $posts_per_page, $wpdb;
global $paged, $result, $request, $posts_per_page, $wpdb, $max_num_pages;
if (!$max_page) {
if ( isset($max_num_pages) ) {
$max_page = $max_num_pages;
} else {
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
$max_page = ceil($numposts / $posts_per_page);
$max_page = $max_num_pages = ceil($numposts / $posts_per_page);
}
}
if (!$paged)
$paged = 1;
@ -486,19 +490,21 @@ function previous_posts_link($label='« Previous Page') {
}
function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
global $request, $posts_per_page, $wpdb;
global $request, $posts_per_page, $wpdb, $max_num_pages;
if (! is_single()) {
if (get_query_var('what_to_show') == 'posts') {
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
$max_page = ceil($numposts / $posts_per_page);
if ( ! isset($max_num_pages) ) {
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
$max_num_pages = ceil($numposts / $posts_per_page);
}
} else {
$max_page = 999999;
$max_num_pages = 999999;
}
if ($max_page > 1) {
if ($max_num_pages > 1) {
previous_posts_link($prelabel);
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
next_posts_link($nxtlabel, $max_page);