WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.19k forks source link

Term Query Loop Block #49094

Open tomjn opened 1 year ago

tomjn commented 1 year ago

What problem does this address?

Currently you can create a tag cloud, and there's a post term list, but these options are limited, and come in 2 versions ( one for the current post, and one that's just general ). If I need to build anything that deviates from this I'm forced to build a new block.

E.g. if I want to display terms with their term descriptions, or add a graphic next to each tag, sort terms into columns, etc, I can't do that with core blocks. Or even spread terms out in a row the same way a group/row block can.

e.g. creating this type of category list automatically is not possible with the core blocks:

Politics

News articles about politics

Sports

The latest sports news

What is your proposed solution?

Instead, A term query block similar to the post query block would be very useful, with term title, term description etc blocks.

This way the existing core blocks could be constructed in any shape form or layout by the users choice without writing code. E.g. using headings for tags with descriptions, custom term featured image blocks in plugins, adding icons, etc

Variants of the block could be registered for each taxonomy too:

Screenshot 2023-03-15 at 12 32 45
MaggieCabrera commented 1 year ago

+1 on this. It's a very common pattern for themes that we can't really work around right now. A good example is the section By Topic on Blue Note, a community theme currently in development: https://github.com/WordPress/community-themes/issues/5

scruffian commented 1 year ago

The query look actually allows for this already. You can filter the query loop based on a tag or a category:

Screenshot 2023-06-08 at 14 35 36
tomjn commented 1 year ago

@scruffian you've misunderstood, this issue is not about displaying posts in a term, it's about displaying the terms themselves!

E.g. it would not produce a post list, it could produce a tag list like this:

Screenshot 2023-06-08 at 14 56 20

Or more complex items, e.g. a heading with a read more button underneath with a term description

scruffian commented 1 year ago

Ah thanks, I thought I must be missing something!

huubl commented 1 year ago

+1 this! Are there any updates/decisions made about adding this new block?

scruffian commented 1 year ago

+1 this! Are there any updates/decisions made about adding this new block?

We want it, we just need someone to build it!

tomjn commented 1 year ago

Noting that this will need scoping out by an engineer to figure out exactly what needs to be done, it's not as simple as asking for it to be done then someone doing it.

For example, issues for at least these blocks would need to be created:

People can probably think of more such as a term slug block but these seem to be the MVP, and each of those will require its own issue and dependencies.

I can also see API changes being desirable re: variations. Afterall if you use a category loop you don't expect a term template, you expect a category template, and a category name/title, making those blocks dependent.

There's also the possibility that because the terms are different entities that it might require taxonomy specific blocks be registered or variants for each taxonomy so that they know which entity type to access and can display the right information.

For those versed in agile, this is more like a spike than an implementation ticket, help/contributions needed for specification

tomjn commented 1 year ago

+1 this! Are there any updates/decisions made about adding this new block?

This is pretty straight forward to answer. Unless you see PRs mentioned here then there has been no work done to build this. If you can't see any decision making then that means no decision making took place.

If there were a place were decisions were made related to this that didn't filter down it'd be the public weekly editor meetings, but someone would have to raise it on the agenda, and it's highly unlikely the info wouldn't filter over to here. Unless someone made another issue and that one got traction instead.

annezazu commented 1 year ago

Punting to 6.5 for consideration since we're four weeks away from beta 1.

annezazu commented 9 months ago

Punted for the same reason as before. This is going to take intentional effort to get done so if anyone is interested for 6.6, please speak up!

skorasaurus commented 8 months ago

I'm working with term meta and terms for the first time in several years (or ever?) and came across this issue while reviewing what capabilities exist in Gutenberg in order to find a block that would display all terms that exist for a particular taxonomy across an entire website.

Even after some research about the current state of such a block; I was a bit confused and found this issue which heavily overlaps with https://github.com/WordPress/gutenberg/issues/33302 (This is cross-posted in #33302 as well).

I include some notes in case anyone else has the same issue or is trying to triage this issue:

Categories block - lists all terms that exist for the taxonomy 'category' across an entire website. In the block inserter and list view, the block is called 'Categories List' Block markup: <!-- wp:categories /--> Only can select the 'category' taxonomy

Post Terms block - lists the terms that are assigned for a taxonomy (selected in the attribute field) on a particular post or page In the block inserter and list view; these blocks are named "Categories" or "tags" <!-- wp:post-terms {"term":"category"} /--> or <!-- wp:post-terms {"term":"post_tag"} /-->

If you register a custom taxonomy, a block variation for the post terms block is registered. It appears in the block inserter and list view as "Name of your taxonomy(s)"

Tag cloud - lists all of the terms that exist for the taxonomy "post_tag" across an entire website. in the block inserter and list view, the block is called 'Tag Cloud'; displays it in a cloud like format.
Only can select the taxonomies 'category' and 'post_tag'

or

There are a couple existing PRs https://github.com/WordPress/gutenberg/pull/58033 & https://github.com/WordPress/gutenberg/pull/26555 that modifies the categories block to select any taxonomy and displays all of that taxonomy's terms on the website.

Going forward in the long-term: I think a new flexible block(s) would probably be appropriate as Tom described at https://github.com/WordPress/gutenberg/issues/49094#issue-1625439496

There is a separate block under development - https://github.com/mattyza/terms-list-block but I haven't examined it.

aaroncommand commented 6 months ago

@skorasaurus has perfectly described what we and doubtless thousands of other developers need as well - a block that would display all terms which exist for a particular taxonomy. (Ideally with some straightforward way to modify the query being run by that block, so we could filter it by children of a particular term, etc.) It's baffling to me that custom taxonomies are such a fundamental feature of WordPress, people have been asking for some variant of this request for years, and yet resources are being spent to building a real-time multi-user version of Gutenberg or whatever instead of creating this block. For now we are probably just going to hack this up in PHP and punt on the template being block-editor-friendly, since in the old world this is basically just a call to get_terms() that takes two minutes to write.

tomjn commented 6 months ago

@aaroncommand he's only in charge of spending his own personal time that's contributed and volunteered here, there's no corporate decision delaying this from being built or product roadmap that punted this.

For this to move forward what's needed is for an engineer to scope out what has to happen so that others know what to do and where to do it. Building this for a single client/customer is easier than making sure this gets built properly for core as tiny engineering decisions can have huge ramifications.

Any support you can show will help here enormously even if it only answers part of the puzzle

colorful-tones commented 5 months ago

Hi folks, We are only one week away from the Beta 1 cut-off date for WordPress 6.6. This issue hasn’t seen any movement in a while, so we (the editor triage leads of the 6.6 release) have decided to remove it from the WordPress 6.6 Editor Tasks project board.

noisysocks commented 5 months ago

Ran into this while creating a block theme. Definitely a big limitation. There's currently no nice way to create a section like this in a block theme:

Screenshot 2024-06-04 at 14 41 03

Instead of a new block, could Categories and Tags be an option in the Query Loop block's settings? I suppose maybe not since there'd need to be an accompaniment of related inner blocks e.g. Taxonomy Title and Taxonomy Count.

ntsekouras commented 5 months ago

Instead of a new block, could Categories and Tags be an option in the Query Loop block's settings? I suppose maybe not since there'd need to be an accompaniment of related inner blocks e.g. Taxonomy Title and Taxonomy Count.

We cannot use Query Loop. We'd need to update some existing term blocks and add new ones.

kauaicreative commented 4 months ago

Came across this implementation of a Term query loop - elegant! https://brickslabs.com/how-to-list-your-posts-divided-by-categories/ Excited for this! 🔥

tomjn commented 4 months ago

@kauaicreative that's using the bricks page builder not Gutenberg

kauaicreative commented 4 months ago

@kauaicreative that's using the bricks page builder not Gutenberg

Yes, bricks. I have not personally used Bricks - but the implementation may offer some inspiration:

  1. A single Query Block allows one to query either terns or posts e.g. Choose Terms as query Type and Categories as the taxomomy.
  2. It allows for nested query loops which is explained in the referenced tutorial link.