Changeset 3646
- Timestamp:
- 03/20/2006 07:43:57 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/template-functions-links.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/template-functions-links.php
r3590 r3646 427 427 428 428 function next_posts_link($label='Next Page »', $max_page=0) { 429 global $paged, $ result, $request, $posts_per_page, $wpdb, $max_num_pages;429 global $paged, $wpdb; 430 430 if ( !$max_page ) { 431 if ( isset($max_num_pages) ) { 432 $max_page = $max_num_pages; 433 } else { 434 preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); 435 $fromwhere = $matches[1]; 436 $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere"); 437 $max_page = $max_num_pages = ceil($numposts / $posts_per_page); 438 } 431 $max_page = _max_num_pages(); 439 432 } 440 433 if ( !$paged ) … … 470 463 } 471 464 465 function _max_num_pages() { 466 static $max_num_pages; 467 global $wpdb, $wp_query; 468 469 if (isset($max_num_pages)) return $max_num_pages; 470 471 if ( 'posts' == get_query_var('what_to_show') ) { 472 preg_match('#FROM\s(.*)\sGROUP BY#siU', $wp_query->request, $matches); 473 $fromwhere = $matches[1]; 474 $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere"); 475 return ceil($numposts / get_option('posts_per_page')); 476 } else { 477 $posts = $wp_query->posts; 478 preg_match('#WHERE\s(.*)\sGROUP BY#siU', $wp_query->request, $matches); 479 $where = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]); 480 $num_days = $wpdb->query("SELECT DISTINCT post_date FROM $wpdb->posts WHERE $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date)"); 481 return ceil($num_days / get_option('posts_per_page')); 482 } 483 } 484 472 485 function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') { 473 global $request, $posts_per_page, $wpdb, $max_num_pages;474 486 if ( !is_single() ) { 475 476 if ( 'posts' == get_query_var('what_to_show') ) { 477 if ( !isset($max_num_pages) ) { 478 preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); 479 $fromwhere = $matches[1]; 480 $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere"); 481 $max_num_pages = ceil($numposts / $posts_per_page); 482 } 483 } else { 484 $max_num_pages = 999999; 487 $max_num_pages = _max_num_pages(); 488 $paged = get_query_var('paged'); 489 490 //only have sep if there's both prev and next results 491 if ($paged < 2 || $paged >= $max_num_pages) { 492 $sep = ''; 485 493 } 486 494 … … 488 496 previous_posts_link($prelabel); 489 497 echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep); 490 next_posts_link($nxtlabel , $max_page);498 next_posts_link($nxtlabel); 491 499 } 492 500 }
Note: See TracChangeset
for help on using the changeset viewer.