Make WordPress Core

Opened 10 years ago

Closed 3 weeks ago

Last modified 3 weeks ago

#35326 closed enhancement (fixed)

New taxonomy template

Reported by: sebastianpisula's profile sebastian.pisula Owned by: jorbin's profile jorbin
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)

35326.patch (571 bytes) - added by sebastian.pisula 10 years ago.
35326.diff (441 bytes) - added by jorbin 4 months ago.
35326-taxonomy-template-by-termid.diff (875 bytes) - added by sachinrajcp123 3 months ago.

Download all attachments as: .zip

Change History (18)

#1 follow-up: @swissspidy
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

category-{$category->term_id}.php and tag-{$tag->term_id}.php exist as well, but after the slug variant.

So adding taxonomy-$taxonomy-{$term->term_id}.php seems legit (not taxonomy-{$term->term_id}.php)

Example:

$templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; 
$templates[] = "taxonomy-$taxonomy-{$term->term_id}.php"; 
Last edited 10 years ago by swissspidy (previous) (diff)

#3 in reply to: ↑ 1 @sebastian.pisula
10 years ago

WordPress 4.5.0 ? :)

Replying to swissspidy:

category-{$category->term_id}.php and tag-{$tag->term_id}.php exist as well, but after the slug variant.

So adding taxonomy-$taxonomy-{$term->term_id}.php seems legit (not taxonomy-{$term->term_id}.php)

Example:

$templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; 
$templates[] = "taxonomy-$taxonomy-{$term->term_id}.php"; 

#4 follow-up: @theMikeD
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: @swissspidy
10 years ago

Replying to theMikeD:

@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?

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 @theMikeD
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 $taxonomy in taxonomy-$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.php is 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.php would 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.

#7 @swissspidy
9 years ago

  • Keywords dev-feedback added

@jorbin
4 months ago

#8 @jorbin
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 @sachinrajcp123
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 @wildworks
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 @jorbin
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

#14 @jorbin
3 weeks ago

  • Owner set to jorbin
  • Resolution set to fixed
  • Status changed from new to closed

In 60994:

Themes: Add a new taxonomy template.

This uses the same cascade as tags and categories so the check will first be for the slug first, then the term ID,

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.

Props swissspidy, sebastian.pisula, jorbin, theMikeD.
Fixes #35326.

#15 @westonruter
3 weeks ago

In 60998:

Themes: Update Tests_Template::test_taxonomy_template_hierarchy to account for new taxonomy template.

Follow-up to [60994].

See #35326.

Note: See TracTickets for help on using tickets.