-
Notifications
You must be signed in to change notification settings - Fork 58
feat: add support for displaying tags as labels #4381
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: trunk
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR adds functionality to display selected post tags as labels, similar to how categories are displayed. The feature includes an admin interface for enabling tags as labels with optional custom label text, and works in conjunction with a companion PR in the newspack-theme repository.
- Added a new Tag_Labels class that manages tag label settings via term meta
- Created admin UI fields to enable tags as labels and customize label text
- Added helper methods for themes to retrieve tag labels for display
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
| src/other-scripts/tag-labels/index.js | Adds jQuery-based client-side logic to enable/disable the label flag input based on checkbox state |
| includes/tag-labels/class-tag-labels.php | Implements the core Tag_Labels class with admin UI, data storage, and helper methods for retrieving tag labels |
| includes/class-newspack.php | Includes the new tag-labels class file to integrate it into the plugin |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
leogermani
left a comment
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 looking good Jason, thanks for the work! I left some minor comments in the code.
I'll tag @thomasguillot and add a needs-design review for him to have a look and answer your questions around presentation. I think it should follow what Sponsors do as much as possible (which is to display the label above the title). Thomas, please also share your thought on how we name and present this feature in the UI. Is "Labels" a good name?
I also have an existencial question I'll copy for @laurelfulford : Since this is very tied to the theme, should this whole thing live in the theme instead? WDYT?
| * | ||
| * @return bool | ||
| */ | ||
| public static function is_tag_label( $term ) { |
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 has_tag_label (or even just has_label) be a better name here? I was confused
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.
Yeah, named this expecting a tag would be of a type 'label', but has may be better. I'm leaning toward _tag_label over just _label because 'label' is a bit of a generic term on its own.
Seeing as you asked whether 'labels' is even appropriate, let's see what folks say about it.
How come we don't have the checkbox and the label flag field when first creating? I must admit I thought I hadn't switched branch and it wasn't working at first. |
Thanks, @thomasguillot! That was a potential issue I flagged, and based on your and @leogermani's comments, I think it'll be worth making those options visible on creation. |
|
"Labels" works well. It's intuitive, distinct from the existing "Tags" terminology, and commonly understood in editorial contexts I think. For the fields, I'd suggest: (ae531b4) Checkbox: "Display as label" with help text: Show this tag as a highlighted label wherever posts are displayed. |
|
All Submissions:
Changes proposed in this Pull Request:
This PR is one of a pair that adds the ability to display selected tags as labels. Changes live in the
feat/tag-labelstopic branch on the newspack-plugin and newspack-theme projects.See also: Automattic/newspack-theme#2613
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).
Addresses NPPD-383: "Breaking News" or "Developing" Label.
Open issues:
phpcs:ignoredirectives with explanatory comments elsewhere.How to test the changes in this Pull Request:
These instructions will be pretty much identical between these two PRs--if you've tested one, you've tested the other.
Basic operation:
Multiple labels:
Custom label text (flag):
Extra credit--plugin mismatch:
trunk.feat/tag-labelstopic branch.trunk.Other information: