-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add terms list block #27
Conversation
$p = new WP_HTML_Tag_Processor( $items_markup ); | ||
|
||
while ( $p->next_tag( 'a' ) ) { | ||
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); | ||
} | ||
$processed_items_markup = $p->get_updated_html(); |
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 is the part that adds the Interactivity API's data-wp-on--click
directive in order to opt the block into client-side navigation, when enabled on the surrounding query block.
We could consider removing it and leaving it up to the developer to add it via the render_block
filter, as we've done here for the Categories block.
IMO, that'd be reasonable, as it's a simple enough change that might not always be needed. There'd still be value in having a Taxonomies block that works with any taxonomy, rather than just categories, which is what Core's Categories List block currently offers 🙂
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.
(One argument for removing the client-side navigation-specific code could be that we'd preserve closer parity to Core's Categories List block, on which this block is based; which might make it easier to eventually swap out this block for Core's, whenever it finally supports custom taxonomies.)
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.
Thanks for the feedback! All of this makes sense to me. I've changed the block to remove the directives 👍
Quick update, I've merged a Gutenberg PR to extend the Core "Categories List" block to allow selecting a custom taxonomy: WordPress/gutenberg#65272. It should be shipped with Gutenberg 19.3 and WordPress 6.7. |
This has merged into core (thanks @ockham !) No need for it to live here also :) |
What
This block renders a list of all the terms associated with a user-selected taxonomy.
Why
Displaying a list of terms from a custom taxonomy is a common requirement for websites and is not currently supported in core.
How
It reimplements the Terms List Block based on the most recent version of the core
core/categories
block.How to Test
Add a Terms List block to any post or template and test to see if you can select different taxonomies, and that all of the block settings (display as dropdown, show post counts, show empty terms, etc.) all work as expected.
terms-block.mp4