Skip to content
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

Closed
wants to merge 8 commits into from
Closed

Conversation

artemiomorales
Copy link
Collaborator

@artemiomorales artemiomorales commented Aug 12, 2024

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

Comment on lines 77 to 82
$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();
Copy link

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 🙂

Copy link

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.)

Copy link
Collaborator Author

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 👍

@artemiomorales artemiomorales changed the title Add taxonomies list block with directives to support client side navigation Add terms list block Aug 13, 2024
@artemiomorales artemiomorales marked this pull request as ready for review August 13, 2024 10:44
@ockham
Copy link

ockham commented Sep 19, 2024

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.

@tommusrhodus
Copy link
Contributor

This has merged into core (thanks @ockham !)

No need for it to live here also :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants