#35326 closed enhancement (fixed)
New taxonomy template
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Themes | Keywords: | has-patch needs-refresh needs-docs needs-dev-note |
| Focuses: | template | Cc: |
Description
I sugest neww taxonomy template: taxonomy-{$term->term_id}.php.
taxonomy-$taxonomy-{$term->slug}.php is bad because if I change slug then I must remember about change filename. In my website this isn't problem but if client change name on website then will be problem.
Attachments (3)
Change History (18)
#1
follow-up:
↓ 3
@
10 years ago
- Component changed from Themes to Taxonomy
- Focuses template added
- Keywords has-patch needs-refresh added
- Milestone changed from Awaiting Review to Future Release
#3
in reply to:
↑ 1
@
10 years ago
WordPress 4.5.0 ? :)
Replying to swissspidy:
category-{$category->term_id}.phpandtag-{$tag->term_id}.phpexist as well, but after the slug variant.
So adding
taxonomy-$taxonomy-{$term->term_id}.phpseems legit (nottaxonomy-{$term->term_id}.php)
Example:
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; $templates[] = "taxonomy-$taxonomy-{$term->term_id}.php";
#4
follow-up:
↓ 5
@
10 years ago
@swissspidy since term IDs are now unique thanks to all the term splitting, why do we need $taxonomy in taxonomy-$taxonomy-{$term->term_id}.php?
#5
in reply to:
↑ 4
;
follow-up:
↓ 6
@
10 years ago
Replying to theMikeD:
@swissspidy since term IDs are now unique thanks to all the term splitting, why do we need
$taxonomyintaxonomy-$taxonomy-{$term->term_id}.php?
I suggested it because of consistency.
First, there's already taxonomy-$taxonomy-{$term->slug}.php, so adding a template with the ID makes sense. Second, this helps developers figuring out what's going on. For example, taxonomy-123.phpsounds like it's the template for a taxonomy with the ID 123. taxonomy-color-123.php is more obvious.
Finally, when the taxonomy name can be left out, term-123.php would make more sense. But again, this would not be consistent with the existing templates..
#6
in reply to:
↑ 5
@
10 years ago
Replying to swissspidy:
Replying to theMikeD:
@swissspidy since term IDs are now unique thanks to all the term splitting, why do we need
$taxonomyintaxonomy-$taxonomy-{$term->term_id}.php?
I suggested it because of consistency.
First, there's already
taxonomy-$taxonomy-{$term->slug}.php, so adding a template with the ID makes sense.
In the case of a slug it's needed because two terms in different taxonomies can have the same slug. This isn't true for IDs.
Second, this helps developers figuring out what's going on. For example,
taxonomy-123.phpsounds like it's the template for a taxonomy with the ID 123.taxonomy-color-123.phpis more obvious.
This is in direct opposition to how term splitting is being done, specifically how the taxonomy field is being stripped from term functions. Why the inconsistency? IMHO I think it's fair to expect developers to read the template docs to determine how they work without needing this type of hand holding.
Finally, when the taxonomy name can be left out,
term-123.phpwould make more sense. But again, this would not be consistent with the existing templates.
If clarity is the goal, consider what we already have:
category-{$category->term_id}.php
tag-{$tag->term_id}.php
Using taxonomy-{$term->term_id}.php or $taxonomy-{$term->term_id}.php is more consistant with the category and tag template names than taxonomy-$taxonomy-{$term->term_id}.php
If consistency is the goal, IMHO you have two choices:
category-{$category->term_id}.php
tag-{$tag->term_id}.php
$taxonomy-{$term->term_id}.php
or
taxonomy-category-{$category->term_id}.php
taxonomy-tag-{$tag->term_id}.php
taxonomy-$taxonomy-{$term->term_id}.php
Or we can use term-{$term->term_id}.php, have it called after category-{$category->term_id}.php, tag-{$tag->term_id}.php in the hierarchy, and not only is this issue solved but we can look forward to eventually phasing out the category- and tag-specific templates and simplifying the hierarchy. All thanks to term splitting.
#8
@
4 months ago
- Milestone changed from Future Release to 6.9
Perfect consistency and maintaining backwards compatibility are sometimes going to be at odds, which can lead to the stalling here. I think the answer is to add taxonomy-$taxonomy-{$term->term_id}.php to the cascade after the slug since for tags and categories slug comes first.
#9
@
3 months ago
Add support for taxonomy-{$term->term_id}.php template to allow stable template targeting regardless of term slug changes.
This ticket was mentioned in Slack in #core by welcher. View the logs.
6 weeks ago
This ticket was mentioned in Slack in #core by wildworks. View the logs.
3 weeks ago
#12
@
3 weeks ago
This ticket was featured on today's 6.9 Bug Scrub.
Maybe @jorbin will take a look at this ticket if he has time.
#13
@
3 weeks ago
- Component changed from Taxonomy to Themes
- Keywords needs-docs needs-dev-note added; dev-feedback removed
While it relates to taxonomies, this change actually affects themes so moving to that component.
This should get a mention in the misc dev note, so adding needs-dev-note. First draft:
New Classic Themes Template for Taxonomy Terms
In classic themes, you can now use term IDs when creating taxonomy templates. With taxonomy-$taxonomy-{$term->term_id}.php templates you don't need to worry about templates breaking if you rename the Oakland Athletics term to Athletics the way you do if you use slug based template names.
https://developer.wordpress.org/themes/classic-themes/basics/template-hierarchy/ will need to be updated (including the image) so adding needs-docs
category-{$category->term_id}.phpandtag-{$tag->term_id}.phpexist as well, but after the slug variant.So adding
taxonomy-$taxonomy-{$term->term_id}.phpseems legit (nottaxonomy-{$term->term_id}.php)Example:
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; $templates[] = "taxonomy-$taxonomy-{$term->term_id}.php";