feat: add tag labels support to Content Loop block#2282
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for displaying selected tags as labels in the Content Loop block (Homepage Articles block). The feature allows tags to be designated as "labels" that appear above post headlines, with customizable text and colors.
Changes:
- Added backend methods to retrieve and format tag labels for posts
- Integrated tag labels into the REST API response for posts
- Updated the Content Loop block template and editor preview to display tag labels
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| includes/class-newspack-blocks.php | Added three new methods: get_tag_labels(), generate_tag_labels(), and display_tag_labels() to retrieve and render tag labels |
| includes/class-newspack-blocks-api.php | Added newspack_blocks_get_tag_labels() method and integrated tag labels into the posts REST API endpoint |
| src/blocks/homepage-articles/templates/article.php | Updated template to retrieve and display tag labels for each post |
| src/blocks/homepage-articles/edit.tsx | Added rendering logic for tag labels in the block editor preview |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Feature works well. A few inline notes, plus one scope suggestion: the Carousel block shares the same REST API data as Homepage Articles but does not render tag labels yet -- worth considering as a follow-up so the label experience is consistent across both content blocks.
|
Swapping the labels since this seems to need some additional work. |
dkoo
left a comment
There was a problem hiding this comment.
Echoing @adekbadek's comment that handling for tag labels is missing from the Carousel block. Aside from that, all is working as described.
dkoo
left a comment
There was a problem hiding this comment.
Whoops, hit the "Approved" button too eagerly. Latest changes for the "Show tag labels" attribute look good, but still need to add support for the Post Carousel block (or follow up in a separate PR).
|
Thanks, @dkoo! We'll tackle the Carousel in a separate PR to avoid scope creep. |
wil-gerken
left a comment
There was a problem hiding this comment.
Tested the feature end-to-end in an isolated env with the feat/tag-labels branches for the plugin, blocks, and theme, plus seeded tags. Everything I checked works great: per-tag enable, custom vs. default label text, control tags correctly left off, the editor/REST data path, front-end rendering, the block toggle, and the customizer color with auto-contrast (light backgrounds get dark text, dark backgrounds get light text). The defensive class_exists() / method_exists() guards are spot-on, so this is safe to land ahead of the plugin and theme PRs — it renders nothing until they do. Nice work.
A few non-blocking notes below — none need to hold the merge; the first is a product call that's entirely yours to make.
wil-gerken
left a comment
There was a problem hiding this comment.
I re-checked the new commits, and all notes are handled: generate_tag_labels() dropped, the REST-shape tests added and passing (nice, you covered both the shape and the empty case), and the default-on toggle kept with a clear rationale. The perf gate is a great catch too. Thanks Jason!
Carousel block slated as a followup PR; otherwise, all requirements appear to be met.
|
Hey @jason10lee, good job getting this PR merged! 🎉 Now, the Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label. If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label. Thank you! ❤️ |
All Submissions:
Changes proposed in this Pull Request:
This PR is one of a set that adds the ability to display selected tags as labels. Changes live in the
feat/tag-labelstopic branch on the newspack-blocks, newspack-plugin, and newspack-theme projects.See also: Automattic/newspack-theme#2613
See also: Automattic/newspack-plugin#4381
Labels will appear above the headline, after any category or sponsorship labels.
By default, the text of the tag label will be the same as the tag name. Optionally, the label text can be customized (e.g., to something shorter and more suitable for use as a label). Additionally, the label color can be customized in the Newspack Theme customizer.
Addresses NPPD-383: "Breaking News" or "Developing" Label.
How to test the changes in this Pull Request:
Basic operation:
Multiple labels:
Custom label text (flag):
Custom label color:
Other information: