-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Add Term Template block #70747
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
base: add/terms-query-block-container
Are you sure you want to change the base?
Add Term Template block #70747
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +1.54 kB (+0.08%) Total Size: 1.91 MB
ℹ️ View Unchanged
|
Flaky tests detected in 7d9b497. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/16678873993
|
$query = $query_block_context['termQuery']; | ||
|
||
$query_args = array( | ||
'per_page' => $query['perPage'] ?? 100, |
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.
Are these defaults the same as anywhere else in WordPress, or just ones you chose?
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.
At the moment, these are just values I've chosen that I thought made the most sense for this block.
For per_page
, I don't think this has a default value. It could be set to the global option with get_option('posts_per_page')
, or it might be worth adding a max number control immediately to the Terms Query block, and the control could have a reasonable default.
if ( isResolving ) { | ||
return ( | ||
<p { ...blockProps }> | ||
<Spinner /> |
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.
Is Spinner
the best placeholder here? Could we use something that matches the format/layout of the block?
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 idea, thanks! I've added some grey placeholders in list items in 0f82d3b:
Screen.Recording.2025-08-01.at.12.40.53.mov
I've used a similar animation to what's currently used in the Navigation and LinkControl blocks. It might need some tweaking but I prefer this to the spinner.
$children_content = render_block_core_term_template_hierarchical( $terms, $block, $term->term_id ); | ||
|
||
if ( ! empty( $children_content ) ) { | ||
$term_content = str_replace( '</li>', '<ul>' . $children_content . '</ul></li>', $term_content ); |
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.
Would it be worth using the WordPress HTML API for this, rather than string manipulation?
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.
This may be moot because filtering to only children of a specific term should happen at the query level.
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.
I don't think the HTML API can handle content replacement; I can't see a way to pass the content into the new processed HTML. But I'm not certain! Maybe there is a way to do this.
…-block # Conflicts: # packages/block-library/src/terms-query/terms-query-content.js
70a9e9a
to
7d9b497
Compare
What?
Part of #49094.
This adds a new block called Term Template, to be used as an inner block in Terms Query. This can be tested as part of a larger PR at #70682.
Why?
To allow for more options and flexibility when displaying terms.
How?
This provides a template for each term to be displayed. For now, I've just rendered the term name in an
<li>
so there is some basic content for testing. We should replace this with an inner block in a follow-up PR.Testing Instructions
Screenshots or screencast