-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comment Template: Add handling for the pagination inner blocks #36623
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! By the way, for now we're not gonna follow the discussion settings because of #36065 (comment) as comnfirmed by Mario in #36065 (comment). I have tried implementing that already and hit that issue.
$comment_args = array( | ||
'number' => $per_page, | ||
'orderby' => 'comment_date_gmt', | ||
'order' => 'ASC', | ||
'status' => 'approve', | ||
'post_id' => $post_id, | ||
'offset' => 0, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those values correspond exactly to the combined defaults of https://developer.wordpress.org/reference/functions/get_approved_comments/ and https://developer.wordpress.org/reference/classes/wp_comment_query/__construct/. This is why I didn't specify them, but perhaps it's better to be explicit about them like you did here. I don't really have the experience to say if one is better than the other or perhaps it doesn't matter 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that doesn't matter. I took it from comments_template() function. It would be ideal that orderby
, order
and status
would be options on the block editor or the discussion settings, maybe for that reason we have it that way in the template.
With get_approved_comments()
, showing not approved comments would not be an option I guess.
We should be able to change it without any problem as get_approved_comments()
also has the $args argument.
'offset' => 0, | ||
); | ||
|
||
if ( $page ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under what circumstances would get_query_var( 'cpage' );
be falsy here and why would that mean that we should return only the count of the comments? Asking out of ignorance here :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go to http://localhost:8888/hello-world/
that is falsy. We get the comments count in order to calculate which should be the offset in order to show the last comments.
For example, if you have 14 comments with 2 comments per page, show the 2 last ones. If you have 13 comments with 2 comments per page, show only one on the last page.
This, to be honest, I could not get it to work yet 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I missed your comment earlier. I think I get it now, thanks 😊
9a7f3d7
to
1381ab4
Compare
b19c619
to
8c7fc88
Compare
8c7fc88
to
399d308
Compare
Updated with a Loom Video |
It looks like this PR needs to be rebased with the latest changes from |
96afd17
to
3f68980
Compare
This is what I see on my test site: Screen.Recording.2021-11-29.at.16.29.17.movIt looks different than the shared recording. Any idea what I do differently? |
I recorded that video using a post page. Not a site editor template. I will try to do the same in order to check if there could be any issue there. Also, the per page for pagination is set up by the comment query loop, not the settings page (I put the same on both in order to navigate with the default one) My comments are appearing, but maybe, on site editor, the Comment Query Loop is not working as expected. If we put a Comment Query Loop on a page that lists more than one post. We should show the Comment Query Loop per Post, right? Right now, I'm not really sure of which |
It's going to be used mostly inside the single page template so we need to ensure it is able to read the currently selected post id. In the case of the post content, we definitely set the post id and post type in the block context. It might be also the case for the site editor when visiting the frontend. It feels like it uses different values for the limit of comments to show. |
@michalczaplinski, do you know what's missing in this PR. Is it something we can team up and finish while Carlos enjoys his time off? |
I haven't followed closely so I don't actually know what's still missing at the moment. I ll take a look tomorrow 🙂 |
I ended up working on pagination handling enhancements and simplification for the block context values passed to inner blocks in #37196. I'm still learning how it all should work, so we can decide later on the next steps. |
@c4rl0sbr4v0, do you plan any further work in this PR? Some of the aspects were addressed in #37196, but I see that you also have here some missing handling for comments with replies. |
I'm afraid that this PR will need a complete rewrite now that we did a refactor to the Comment Content Component. I think it will be better to close it and create a new one. |
Description
This is a follow-up of #35231 and complements #36065.
I took most of the code from Comments Comment Function
In this PR we add pagination to the comment render, so it can work with future pagination links. It still lacks certain things like:
Orderby
,Order
andStatus
are hardcoded. I'd love to include them as options in next PRs.How has this been tested?
Screenshots
Loom video
Types of changes
New feature.
Checklist:
*.native.js
files for terms that need renaming or removal).