Cache the max number of pages to avoid multiple queries. http://mosquito.wordpress.org/view.php?id=1063
git-svn-id: https://develop.svn.wordpress.org/trunk@2422 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3bacf431ae
commit
9e7ef95b4c
|
@ -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) {
|
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 (!$max_page) {
|
||||||
|
if ( isset($max_num_pages) ) {
|
||||||
|
$max_page = $max_num_pages;
|
||||||
|
} else {
|
||||||
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
|
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
|
||||||
$fromwhere = $matches[1];
|
$fromwhere = $matches[1];
|
||||||
$numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
|
$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)
|
if (!$paged)
|
||||||
$paged = 1;
|
$paged = 1;
|
||||||
|
@ -486,19 +490,21 @@ function previous_posts_link($label='« Previous Page') {
|
||||||
}
|
}
|
||||||
|
|
||||||
function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next 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 (! is_single()) {
|
||||||
|
|
||||||
if (get_query_var('what_to_show') == 'posts') {
|
if (get_query_var('what_to_show') == 'posts') {
|
||||||
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
|
if ( ! isset($max_num_pages) ) {
|
||||||
$fromwhere = $matches[1];
|
preg_match('#FROM (.*) GROUP BY#', $request, $matches);
|
||||||
$numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
|
$fromwhere = $matches[1];
|
||||||
$max_page = ceil($numposts / $posts_per_page);
|
$numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
|
||||||
|
$max_num_pages = ceil($numposts / $posts_per_page);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$max_page = 999999;
|
$max_num_pages = 999999;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($max_page > 1) {
|
if ($max_num_pages > 1) {
|
||||||
previous_posts_link($prelabel);
|
previous_posts_link($prelabel);
|
||||||
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
|
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
|
||||||
next_posts_link($nxtlabel, $max_page);
|
next_posts_link($nxtlabel, $max_page);
|
||||||
|
|
Loading…
Reference in New Issue