From f510f2a85deba347dc03005aa29e2d78e2e4722d Mon Sep 17 00:00:00 2001 From: rboren Date: Mon, 16 Aug 2004 22:50:06 +0000 Subject: [PATCH] Paging cleanup. git-svn-id: http://svn.automattic.com/wordpress/trunk@1536 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit.php | 1 + wp-blog-header.php | 5 +- wp-includes/classes.php | 92 +++++++++++------------- wp-includes/template-functions-links.php | 21 ++++-- 4 files changed, 59 insertions(+), 60 deletions(-) diff --git a/wp-admin/edit.php b/wp-admin/edit.php index b67592df10..caeceb4fd6 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -92,6 +92,7 @@ if( isset( $_GET['m'] ) ) '$otherdate'"; - } - } + // Paging + if ( !empty($q['postend']) && ($q['postend'] > $q['poststart']) ) { + if ($q['what_to_show'] == 'posts') { + $q['poststart'] = intval($q['poststart']); + $q['postend'] = intval($q['postend']); + $limposts = $q['postend'] - $q['poststart']; + $limits = ' LIMIT '.$q['poststart'].','.$limposts; + } elseif ($q['what_to_show'] == 'days') { + $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') { - $q['poststart'] = intval($q['poststart']); - $q['postend'] = intval($q['postend']); - $limposts = $q['postend'] - $q['poststart']; - $limits = ' LIMIT '.$q['poststart'].','.$limposts; - } elseif ($q['what_to_show'] == 'days') { - $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 (($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['what_to_show'] == 'posts')) { + $pgstrt = ''; + $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; + $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; + } elseif ($q['what_to_show'] == 'days') { + $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 - ((intval($page) -1) * ($q['posts_per_page']-1) * 86400))); + $enddate = date('Y-m-d H:i:s', ($lastpostdate - (intval($page) * ($q['posts_per_page']-1) * 86400))); + if ($page > 1) { + $where .= " AND post_date > '$enddate' AND post_date < '$startdate'"; + } else { + $where .= " AND post_date > '$enddate'"; + } + } + } if ($q['p'] == 'all') { $where = ''; diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index f514133a9a..c5094b12dd 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -429,13 +429,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; if (! is_single()) { - $nxt_request = $request; - if ($pos = strpos(strtoupper($request), 'LIMIT')) { + $show_what = get_query_var('what_to_show'); + + if (get_query_var('what_to_show') == 'posts') { + $nxt_request = $request; + if ($pos = strpos(strtoupper($request), 'LIMIT')) { $nxt_request = substr($request, 0, $pos); - } - $nxt_result = $wpdb->query($nxt_request); - $numposts = $wpdb->num_rows; - $max_page = ceil($numposts / $posts_per_page); + } + + $nxt_result = $wpdb->query($nxt_request); + $numposts = $wpdb->num_rows; + $max_page = ceil($numposts / $posts_per_page); + } else { + $max_page = 999999; + } + if ($max_page > 1) { previous_posts_link($prelabel); echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep); @@ -444,5 +452,4 @@ function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nx } } - ?> \ No newline at end of file