Changeset 34729 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 10/01/2015 03:10:13 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r34716 r34729 1241 1241 } 1242 1242 1243 /* 1244 * For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order. 1245 * Since we don't have full pagination info until after the query, we use some tricks to get the 1246 * right comments for the current page. 1247 * 1248 * Abandon all hope, ye who enter here! 1249 */ 1250 $flip_comment_order = $trim_comments_on_page= false; 1243 $comment_args['order'] = 'ASC'; 1251 1244 $comment_args['number'] = $per_page; 1252 1245 $page = (int) get_query_var( 'cpage' ); 1253 if ( 'newest' === get_option( 'default_comments_page' ) ) { 1254 if ( $page ) { 1255 $comment_args['order'] = 'ASC'; 1256 1257 /* 1258 * We don't have enough data (namely, the total number of comments) to calculate an 1259 * exact offset. We'll fetch too many comments, and trim them as needed 1260 * after the query. 1261 */ 1262 $offset = ( $page - 2 ) * $per_page; 1263 if ( 0 > $offset ) { 1264 // `WP_Comment_Query` doesn't support negative offsets. 1265 $comment_args['offset'] = 0; 1266 } else { 1267 $comment_args['offset'] = $offset; 1268 } 1269 1270 // Fetch double the number of comments we need. 1271 $comment_args['number'] += $per_page; 1272 $trim_comments_on_page = true; 1273 } else { 1274 $comment_args['order'] = 'DESC'; 1275 $comment_args['offset'] = 0; 1276 $flip_comment_order = true; 1277 } 1246 1247 if ( $page ) { 1248 $comment_args['offset'] = ( $page - 1 ) * $per_page; 1249 } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) { 1250 $comment_args['offset'] = 0; 1278 1251 } else { 1279 $comment_args['order'] = 'ASC'; 1280 if ( $page ) { 1281 $comment_args['offset'] = ( $page - 1 ) * $per_page; 1282 } else { 1283 $comment_args['offset'] = 0; 1284 } 1252 // If fetching the first page of 'newest', we need a top-level comment count. 1253 $top_level_query = new WP_Comment_Query(); 1254 $top_level_count = $top_level_query->query( array( 1255 'count' => true, 1256 'orderby' => false, 1257 'post_id' => $post->ID, 1258 'parent' => 0, 1259 ) ); 1260 1261 $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; 1285 1262 } 1286 1263 1287 1264 $comment_query = new WP_Comment_Query( $comment_args ); 1288 1265 $_comments = $comment_query->comments; 1289 1290 // Delightful pagination quirk #1: `wp_list_comments()` expects the order to be wrong, so we make it wrong.1291 if ( $flip_comment_order ) {1292 $_comments = array_reverse( $_comments );1293 }1294 1295 // Delightful pagination quirk #2: reverse chronological order requires page shifting.1296 if ( $trim_comments_on_page ) {1297 // Correct the value of max_num_pages, which is wrong because we manipulated the per_page 'number'.1298 $comment_query->max_num_pages = ceil( $comment_query->found_comments / $per_page );1299 1300 // Identify the number of comments that should appear on page 1.1301 $page_1_count = $comment_query->found_comments - ( ( $comment_query->max_num_pages - 1 ) * $per_page );1302 1303 // Use that value to shift the matched comments.1304 if ( 1 === $page ) {1305 $_comments = array_slice( $_comments, 0, $page_1_count );1306 } else {1307 $_comments = array_slice( $_comments, $page_1_count, $per_page );1308 }1309 }1310 1266 1311 1267 // Trees must be flattened before they're passed to the walker.
Note: See TracChangeset
for help on using the changeset viewer.