Make WordPress Core

Opened 10 years ago

Last modified 3 weeks ago

#35326 new enhancement

New taxonomy template

Reported by: sebastianpisula's profile sebastian.pisula Owned by:
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch needs-refresh dev-feedback
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 (2)

35326.patch (571 bytes) - added by sebastian.pisula 10 years ago.
35326.diff (441 bytes) - added by jorbin 3 weeks ago.

Download all attachments as: .zip

Change History (10)

#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
8 years ago

  • Keywords dev-feedback added

@jorbin
3 weeks ago

#8 @jorbin
3 weeks 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.

Note: See TracTickets for help on using tickets.