Make WordPress Core

Changeset 2422


Ignore:
Timestamp:
03/09/2005 04:15:30 AM (19 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/template-functions-links.php

    r2384 r2422  
    449449
    450450function next_posts_link($label='Next Page »', $max_page=0) {
    451     global $paged, $result, $request, $posts_per_page, $wpdb;
     451    global $paged, $result, $request, $posts_per_page, $wpdb, $max_num_pages;
    452452    if (!$max_page) {
     453            if ( isset($max_num_pages) ) {
     454                $max_page = $max_num_pages;
     455            } else {
    453456        preg_match('#FROM (.*) GROUP BY#', $request, $matches);
    454457        $fromwhere = $matches[1];
    455458        $numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
    456         $max_page = ceil($numposts / $posts_per_page);
     459        $max_page = $max_num_pages = ceil($numposts / $posts_per_page);
     460            }
    457461    }
    458462    if (!$paged)
     
    487491
    488492function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') {
    489     global $request, $posts_per_page, $wpdb;
     493    global $request, $posts_per_page, $wpdb, $max_num_pages;
    490494    if (! is_single()) {
    491495
    492496        if (get_query_var('what_to_show') == 'posts') {
    493             preg_match('#FROM (.*) GROUP BY#', $request, $matches);
    494             $fromwhere = $matches[1];
    495             $numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
    496             $max_page = ceil($numposts / $posts_per_page);
     497            if ( ! isset($max_num_pages) ) {
     498                preg_match('#FROM (.*) GROUP BY#', $request, $matches);
     499                $fromwhere = $matches[1];
     500                $numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $fromwhere");
     501                $max_num_pages = ceil($numposts / $posts_per_page);
     502            }
    497503        } else {
    498             $max_page = 999999;
     504            $max_num_pages = 999999;
    499505        }
    500506
    501         if ($max_page > 1) {
     507        if ($max_num_pages > 1) {
    502508            previous_posts_link($prelabel);
    503509            echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);
Note: See TracChangeset for help on using the changeset viewer.