Improve paging by days. Retabify source.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1610 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-09-05 20:00:09 +00:00
parent de4665574b
commit d97d4b74d7
1 changed files with 528 additions and 499 deletions

View File

@ -162,7 +162,7 @@ class WP_Query {
$this->is_page = true; $this->is_page = true;
} }
if ('' != $qv['error'] || '404' == $qv['pagename']) { if ('404' == $qv['error']) {
$this->is_404 = true; $this->is_404 = true;
} }
@ -435,6 +435,32 @@ class WP_Query {
} }
} }
if ($q['p'] == 'all') {
$where = '';
}
$now = gmdate('Y-m-d H:i:59');
if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
if ((empty($q['poststart'])) || (empty($q['postend'])) || !($q['postend'] > $q['poststart'])) {
$where .= " AND post_date_gmt <= '$now'";
}
$distinct = 'DISTINCT';
}
if ('' != $q['static']) {
$where .= ' AND (post_status = "static"';
} else {
$where .= ' AND (post_status = "publish"';
}
// Get private posts
if (isset($user_ID) && ('' != intval($user_ID)))
$where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
else
$where .= ')';
// Paging // Paging
if ( !empty($q['postend']) && ($q['postend'] > $q['poststart']) ) { if ( !empty($q['postend']) && ($q['postend'] > $q['poststart']) ) {
if ($q['what_to_show'] == 'posts') { if ($q['what_to_show'] == 'posts') {
@ -464,50 +490,53 @@ class WP_Query {
$pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
$limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; $limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
} elseif ($q['what_to_show'] == 'days') { } elseif ($q['what_to_show'] == 'days') {
$lastpostdate = get_lastpostdate(); $post_dates = $wpdb->get_col('SELECT post_date FROM ' . $wpdb->posts . ' WHERE (1=1) ' . $where . ' ORDER BY post_date DESC');
$lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate); $number_of_days = $q['posts_per_page'];
$lastpostdate = mysql2date('U',$lastpostdate); $page_number = -1;
$startdate = date('Y-m-d H:i:s', ($lastpostdate - ((intval($page) -1) * ($q['posts_per_page']-1) * 86400))); $day_number = $number_of_days;
$enddate = date('Y-m-d H:i:s', ($lastpostdate - (intval($page) * ($q['posts_per_page']-1) * 86400))); foreach ($post_dates as $post_date) {
if (($day_number % $number_of_days) == 0) {
$previousDay = (int)mysql2date('d', $post_date);
$previousMonth = (int)mysql2date('m', $post_date);
$previousYear = (int)mysql2date('Y', $post_date);
$page_number++;
$day_number = 1;
if ($page_number == $page) {
$end_date = $post_date;
break;
} else {
$start_date = $post_date;
continue;
}
}
$thisDay = (int)mysql2date('d', $post_date);
$thisMonth = (int)mysql2date('m', $post_date);
$thisYear = (int)mysql2date('Y', $post_date);
if (($thisDay != $previousDay) || ($thisMonth != $previousMonth) ||
($thisYear != $previousYear)) {
$previousDay = (int)mysql2date('d', $post_date);
$previousMonth = (int)mysql2date('m', $post_date);
$previousYear = (int)mysql2date('Y', $post_date);
$previous_date = $post_date;
$day_number++;
}
}
if ($page > 1) { if ($page > 1) {
$where .= " AND post_date > '$enddate' AND post_date < '$startdate'"; $where .= " AND post_date > '$end_date' AND post_date <= '$start_date'";
} else { } else {
$where .= " AND post_date > '$enddate'"; $where .= " AND post_date > '$end_date'";
} }
} }
} }
if ($q['p'] == 'all') { echo "where: $where <br />";
$where = '';
}
$now = gmdate('Y-m-d H:i:59');
if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
if ((empty($q['poststart'])) || (empty($q['postend'])) || !($q['postend'] > $q['poststart'])) {
$where .= " AND post_date_gmt <= '$now'";
}
$distinct = 'DISTINCT';
}
if ('' != $q['static']) {
$where .= ' AND (post_status = "static"';
} else {
$where .= ' AND (post_status = "publish"';
}
// Get private posts
if (isset($user_ID) && ('' != intval($user_ID)))
$where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
else
$where .= ')';
$where = apply_filters('posts_where', $where); $where = apply_filters('posts_where', $where);
$where .= " GROUP BY $wpdb->posts.ID"; $where .= " GROUP BY $wpdb->posts.ID";
$request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY post_" . $q['orderby'] . " $limits"; $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1".$where." ORDER BY post_" . $q['orderby'] . " $limits";
if ($q['preview']) { if ($q['preview']) {
$request = 'SELECT 1-1'; // dummy mysql query for the preview $request = 'SELECT 1-1'; // dummy mysql query for the preview
// little funky fix for IEwin, rawk on that code // little funky fix for IEwin, rawk on that code