Fix comment_order for single page comment threads.
The old comment pagination logic had a separate block for comment threads that appeared on a single page. After the refactoring in [34561], all comment pagination logic is unified. This change ensures that 'comment_order' is respected in all scenarios. Fixes #8071. Built from https://develop.svn.wordpress.org/trunk@34669 git-svn-id: http://core.svn.wordpress.org/trunk@34633 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5bfa878fee
commit
f7f4fb01ab
|
@ -1233,57 +1233,54 @@ function comments_template( $file = '/comments.php', $separate_comments = false
|
||||||
$per_page = (int) get_option( 'comments_per_page' );
|
$per_page = (int) get_option( 'comments_per_page' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$flip_comment_order = $trim_comments_on_page = false;
|
/*
|
||||||
if ( $post->comment_count > $per_page ) {
|
* For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order.
|
||||||
$comment_args['number'] = $per_page;
|
* Since we don't have full pagination info until after the query, we use some tricks to get the
|
||||||
|
* right comments for the current page.
|
||||||
/*
|
*
|
||||||
* For legacy reasons, higher page numbers always mean more recent comments, regardless of sort order.
|
* Abandon all hope, ye who enter here!
|
||||||
* Since we don't have full pagination info until after the query, we use some tricks to get the
|
*/
|
||||||
* right comments for the current page.
|
$flip_comment_order = $trim_comments_on_page= false;
|
||||||
*
|
$comment_args['number'] = $per_page;
|
||||||
* Abandon all hope, ye who enter here!
|
$page = (int) get_query_var( 'cpage' );
|
||||||
*/
|
if ( 'newest' === get_option( 'default_comments_page' ) ) {
|
||||||
$page = (int) get_query_var( 'cpage' );
|
if ( $page ) {
|
||||||
if ( 'newest' === get_option( 'default_comments_page' ) ) {
|
|
||||||
if ( $page ) {
|
|
||||||
$comment_args['order'] = 'ASC';
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We don't have enough data (namely, the total number of comments) to calculate an
|
|
||||||
* exact offset. We'll fetch too many comments, and trim them as needed
|
|
||||||
* after the query.
|
|
||||||
*/
|
|
||||||
$offset = ( $page - 2 ) * $per_page;
|
|
||||||
if ( 0 > $offset ) {
|
|
||||||
// `WP_Comment_Query` doesn't support negative offsets.
|
|
||||||
$comment_args['offset'] = 0;
|
|
||||||
} else {
|
|
||||||
$comment_args['offset'] = $offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch double the number of comments we need.
|
|
||||||
$comment_args['number'] += $per_page;
|
|
||||||
$trim_comments_on_page = true;
|
|
||||||
} else {
|
|
||||||
$comment_args['order'] = 'DESC';
|
|
||||||
$comment_args['offset'] = 0;
|
|
||||||
$flip_comment_order = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$comment_args['order'] = 'ASC';
|
$comment_args['order'] = 'ASC';
|
||||||
if ( $page ) {
|
|
||||||
$comment_args['offset'] = ( $page - 1 ) * $per_page;
|
/*
|
||||||
} else {
|
* We don't have enough data (namely, the total number of comments) to calculate an
|
||||||
|
* exact offset. We'll fetch too many comments, and trim them as needed
|
||||||
|
* after the query.
|
||||||
|
*/
|
||||||
|
$offset = ( $page - 2 ) * $per_page;
|
||||||
|
if ( 0 > $offset ) {
|
||||||
|
// `WP_Comment_Query` doesn't support negative offsets.
|
||||||
$comment_args['offset'] = 0;
|
$comment_args['offset'] = 0;
|
||||||
|
} else {
|
||||||
|
$comment_args['offset'] = $offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fetch double the number of comments we need.
|
||||||
|
$comment_args['number'] += $per_page;
|
||||||
|
$trim_comments_on_page = true;
|
||||||
|
} else {
|
||||||
|
$comment_args['order'] = 'DESC';
|
||||||
|
$comment_args['offset'] = 0;
|
||||||
|
$flip_comment_order = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$comment_args['order'] = 'ASC';
|
||||||
|
if ( $page ) {
|
||||||
|
$comment_args['offset'] = ( $page - 1 ) * $per_page;
|
||||||
|
} else {
|
||||||
|
$comment_args['offset'] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$comment_query = new WP_Comment_Query( $comment_args );
|
$comment_query = new WP_Comment_Query( $comment_args );
|
||||||
$_comments = $comment_query->comments;
|
$_comments = $comment_query->comments;
|
||||||
|
|
||||||
// Delightful pagination quirk #1: first page of results sometimes needs reordering.
|
// Delightful pagination quirk #1: `wp_list_comments()` expects the order to be wrong, so we make it wrong.
|
||||||
if ( $flip_comment_order ) {
|
if ( $flip_comment_order ) {
|
||||||
$_comments = array_reverse( $_comments );
|
$_comments = array_reverse( $_comments );
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-34668';
|
$wp_version = '4.4-alpha-34669';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue