Paging cleanup.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1536 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-08-16 22:50:06 +00:00
parent f3c3e4b218
commit f510f2a85d
4 changed files with 59 additions and 60 deletions

View File

@ -92,6 +92,7 @@ if( isset( $_GET['m'] ) )
</tr> </tr>
<?php <?php
if (empty($m)) $showposts = 15; if (empty($m)) $showposts = 15;
$nopaging = true;
include(ABSPATH.'wp-blog-header.php'); include(ABSPATH.'wp-blog-header.php');
if ($posts) { if ($posts) {

View File

@ -124,11 +124,14 @@ if ( isset($showposts) && $showposts ) {
$showposts = (int) $showposts; $showposts = (int) $showposts;
$posts_per_page = $showposts; $posts_per_page = $showposts;
} }
if ( !isset($nopaging) ) {
$nopaging = '';
}
$archive_mode = get_settings('archive_mode'); $archive_mode = get_settings('archive_mode');
$use_gzipcompression = get_settings('gzipcompression'); $use_gzipcompression = get_settings('gzipcompression');
$more_wpvars = array('posts_per_page', 'what_to_show', 'showposts'); $more_wpvars = array('posts_per_page', 'what_to_show', 'showposts', 'nopaging');
// Construct the query string. // Construct the query string.
$query_string = ''; $query_string = '';

View File

@ -394,59 +394,47 @@ class WP_Query {
} }
} }
if ((!$whichcat) && (!$q['m']) && (!$q['p']) && (!$q['w']) && (!$q['s']) && empty($q['poststart']) && empty($q['postend'])) { // Paging
if ($q['what_to_show'] == 'posts') { if ( !empty($q['postend']) && ($q['postend'] > $q['poststart']) ) {
$limits = ' LIMIT '.$q['posts_per_page']; if ($q['what_to_show'] == 'posts') {
} elseif ($q['what_to_show'] == 'days' && empty($q['monthnum']) && empty($q['year']) && empty($q['day'])) { $q['poststart'] = intval($q['poststart']);
$lastpostdate = get_lastpostdate(); $q['postend'] = intval($q['postend']);
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate); $limposts = $q['postend'] - $q['poststart'];
$lastpostdate = mysql2date('U',$lastpostdate); $limits = ' LIMIT '.$q['poststart'].','.$limposts;
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($q['posts_per_page']-1) * 86400))); } elseif ($q['what_to_show'] == 'days') {
$where .= " AND post_date > '$otherdate'"; $q['poststart'] = intval($q['poststart']);
} $q['postend'] = intval($q['postend']);
} $limposts = $q['postend'] - $q['poststart'];
$lastpostdate = get_lastpostdate();
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
$lastpostdate = mysql2date('U',$lastpostdate);
$startdate = date('Y-m-d H:i:s', ($lastpostdate - (($q['poststart'] -1) * 86400)));
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($q['postend'] -1) * 86400)));
$where .= " AND post_date > '$otherdate' AND post_date < '$startdate'";
}
} else if (empty($q['nopaging']) && ! is_single()) {
$page = $q['paged'];
if (empty($page)) {
$page = 1;
}
if ( !empty($q['postend']) && ($q['postend'] > $q['poststart']) && (!$q['m']) && empty($q['monthnum']) && empty($q['year']) && empty($q['day']) &&(!$q['w']) && (!$whichcat) && (!$q['s']) && (!$q['p'])) { if (($q['what_to_show'] == 'posts')) {
if ($q['what_to_show'] == 'posts') { $pgstrt = '';
$q['poststart'] = intval($q['poststart']); $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
$q['postend'] = intval($q['postend']); $limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
$limposts = $q['postend'] - $q['poststart']; } elseif ($q['what_to_show'] == 'days') {
$limits = ' LIMIT '.$q['poststart'].','.$limposts; $lastpostdate = get_lastpostdate();
} elseif ($q['what_to_show'] == 'days') { $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
$q['poststart'] = intval($q['poststart']); $lastpostdate = mysql2date('U',$lastpostdate);
$q['postend'] = intval($q['postend']); $startdate = date('Y-m-d H:i:s', ($lastpostdate - ((intval($page) -1) * ($q['posts_per_page']-1) * 86400)));
$limposts = $q['postend'] - $q['poststart']; $enddate = date('Y-m-d H:i:s', ($lastpostdate - (intval($page) * ($q['posts_per_page']-1) * 86400)));
$lastpostdate = get_lastpostdate(); if ($page > 1) {
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate); $where .= " AND post_date > '$enddate' AND post_date < '$startdate'";
$lastpostdate = mysql2date('U',$lastpostdate); } else {
$startdate = date('Y-m-d H:i:s', ($lastpostdate - (($q['poststart'] -1) * 86400))); $where .= " AND post_date > '$enddate'";
$otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($q['postend'] -1) * 86400))); }
$where .= " AND post_date > '$otherdate' AND post_date < '$startdate'"; }
} }
} else {
if (($q['what_to_show'] == 'posts') && (! is_single()) && (!$q['more'])) {
if ($pagenow != 'post.php') {
$pgstrt = '';
if ($q['paged']) {
$pgstrt = (intval($q['paged']) -1) * $q['posts_per_page'] . ', ';
}
$limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
} else {
if (($q['m']) || ($q['p']) || ($q['w']) || ($q['s']) || ($whichcat)) {
$limits = '';
} else {
$pgstrt = '';
if ($q['paged']) {
$pgstrt = (intval($q['paged']) -1) * $q['posts_per_page'] . ', ';
}
$limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
}
}
}
elseif (($q['m']) || ($q['p']) || ($q['w']) || ($q['s']) || ($whichcat) || ($q['author']) || $q['monthnum'] || $q['year'] || $q['day']) {
$limits = '';
}
}
if ($q['p'] == 'all') { if ($q['p'] == 'all') {
$where = ''; $where = '';

View File

@ -429,13 +429,21 @@ function previous_posts_link($label='&laquo; Previous Page') {
function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') { function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nxtlabel='Next Page &raquo;') {
global $request, $posts_per_page, $wpdb; global $request, $posts_per_page, $wpdb;
if (! is_single()) { if (! is_single()) {
$nxt_request = $request; $show_what = get_query_var('what_to_show');
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
if (get_query_var('what_to_show') == 'posts') {
$nxt_request = $request;
if ($pos = strpos(strtoupper($request), 'LIMIT')) {
$nxt_request = substr($request, 0, $pos); $nxt_request = substr($request, 0, $pos);
} }
$nxt_result = $wpdb->query($nxt_request);
$numposts = $wpdb->num_rows; $nxt_result = $wpdb->query($nxt_request);
$max_page = ceil($numposts / $posts_per_page); $numposts = $wpdb->num_rows;
$max_page = ceil($numposts / $posts_per_page);
} else {
$max_page = 999999;
}
if ($max_page > 1) { if ($max_page > 1) {
previous_posts_link($prelabel); previous_posts_link($prelabel);
echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep); echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $sep);
@ -444,5 +452,4 @@ function posts_nav_link($sep=' &#8212; ', $prelabel='&laquo; Previous Page', $nx
} }
} }
?> ?>