Skip to content

Commit

Permalink
Adjust to only work with 1st level comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Bravo committed Nov 26, 2021
1 parent 31e58dc commit 399d308
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/block-library/src/comment-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,29 @@ function render_block_core_comment_template( $attributes, $content, $block ) {
}

$per_page = $block->context['queryPerPage'];
// Get an array of comments for the current post.

$page = (int) get_query_var( 'cpage' );

$comment_args = array(
'number' => $per_page,
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'post_id' => $post_id,
'offset' => 0,
'parent_id' => 0,
'number' => $per_page,
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'post_id' => $post_id,
'offset' => 0,
'parent' => 0, // Only show top-level comments. Needs to be updated with responses.
);

if ( $page ) {
$comment_args['offset'] = ( $page - 1 ) * $per_page;
} else {
$top_level_args = array(
'count' => true,
'orderby' => false,
$top_level_args = array(
'post_id' => $post_id,
'status' => 'approve',
'count' => true,
'parent' => 0,
);

// We don't count nested comments yet.
$comment_count = get_comments( $top_level_args );

$comment_args['offset'] = ( ceil( $comment_count / $per_page ) - 1 ) * $per_page;
$top_level_count = get_comments( $top_level_args );
$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
}

$comments = get_comments( $comment_args );
Expand Down

0 comments on commit 399d308

Please sign in to comment.