Skip to content
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

Allow adding templates for a single post with a specific taxonomy/term in the Site Editor. #48264

Open
nefeline opened this issue Feb 20, 2023 · 14 comments
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.

Comments

@nefeline
Copy link
Contributor

What problem does this address?

Currently, it is not possible to add templates for a single post with a specific taxonomy/term in the Site Editor.

What is your proposed solution?

This is a request for making this option available under Templates > Single Item: {post_type}:

Screenshot 2023-02-20 at 22 52 48

On WooCommerce Blocks, we have been exploring different approaches for allowing store owners to add custom templates to individual products depending on their type (simple, grouped, variable, external, etc.). In a nutshell, these are terms of the product_type taxonomy. Ideally, we would like to rely on a more robust long-term solution provided by Gutenberg to achieve this goal: we believe this approach can benefit not only Woo, but basically anyone who intends to have a special template for a single post type given its taxonomy.

@annezazu annezazu added [Type] Enhancement A suggestion for improvement. [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels Feb 20, 2023
@annezazu
Copy link
Contributor

Related discussion around scaling the template interface #42325 cc @jameskoster for your thoughts here (especially with your Woo background).

@jameskoster
Copy link
Contributor

I think the issue here is that the wp template hierarchy does not cater to this use case, and so far as I understand things there's no way to add the necessary logic to something like the single-product template. Perhaps @ntsekouras can offer some input on the technical details.

@ntsekouras
Copy link
Contributor

@jameskoster is right about the template hierarchy and the handling of templates.

This seems to me more of a specific term/taxonomy template, which is already handled from the UI.

@annezazu
Copy link
Contributor

Got it! I'm going to close this out in that case. Happy to re-open if needed.

@nefeline
Copy link
Contributor Author

nefeline commented Mar 2, 2023

Hi there, folks!

Thanks for your responses, I'd like to offer a new point of view here:

I think the issue here is that the wp template hierarchy does not cater to this use case, and so far as I understand things there's no way to add the necessary logic to something like the single-product template. Perhaps @ntsekouras can offer some input on the technical details.

Yes, it is true the native template hierarchy for a single post currently doesn't support this (we also noted this during our exploration), but since on the PHP side, we can rely on a hook (e.g. 'single_template_hierarchy') to extend the native hierarchy, it would be important to be able to visualize those on this modal, if not programmatically (have the new template automatically displayed on this modal), at least provide a way for plugin developers to extend it so we can add/remove templates and customize this area, ensuring it is aligned with the extended template hierarchy. What do you think?

@jameskoster
Copy link
Contributor

This seems to me more of a specific term/taxonomy template, which is already handled from the UI.

I'm not sure that's quite right. I think the use case here is about displaying single entries with a specific term using a unique template, e.g. "I want everything published in the Recipes category to appear this way".

Technically you can already do this by creating a $custom template and applying it manually to all those posts, but that is quite tedious and would have to be done each time you create a new entry. It may still be a short-term solution for you @nefeline ?

There does seem to be a valid use case here, but I'm curious about the hierarchy structure. What would happen if templates existed for different terms in the same taxonomy, but a post was assigned to both terms? IE:

  • All posts in the Recipes category are assigned a template
  • All posts in the Reviews category are assigned a template
  • A post was categorised both as a Recipe and Review

Which template gets used there? How can we communicate this to users? How does the add template modal scale to accommodate many taxonomies / terms?

I'll re-open for now. Easy to close again if we deem this to be plugin territory.

@jameskoster jameskoster reopened this Mar 2, 2023
@crimann
Copy link

crimann commented Mar 7, 2023

The proposed solution by @nefeline would make a lot of sense to me as well. For example, I have a category with "Notes" on my blog, that I want to display differently than other posts. Right now, there's no way (as far as I can tell) rather than:

  • making a Custom Template, and then applying it manually on each note (not practical)
  • moving Notes to a post type instead of a category (which is something I considered anyway, but shouldn't be necessary)

While it's true that in classic themes we did't have a single-{category}.php template, we did have conditionals! For smaller changes (for example: "If post is of a given category -> don't display a title, or author, or date") we were often using the single.php template with conditionals to check for taxonomies/authors and what-not. As we can't use conditionals in the site editor, this does not seem to be possible at the moment.

@nefeline
Copy link
Contributor Author

nefeline commented Mar 8, 2023

Thanks @jameskoster!

Technically you can already do this by creating a $custom template and applying it manually to all those posts, but that is quite tedious and would have to be done each time you create a new entry.

Yes, indeed: While it's possible to manually create custom templates and apply them manually to individual posts, that's suboptimal and doesn't scale: for a website with hundreds/thousands of posts, it can be a challenge to keep up and ensure all individual posts under the same category or term share the same template via manual user input.

There does seem to be a valid use case here, but I'm curious about the hierarchy structure. What would happen if templates existed for different terms in the same taxonomy, but a post was assigned to both terms? IE:

All posts in the Recipes category are assigned a template
All posts in the Reviews category are assigned a template
A post was categorised both as a Recipe and Review
Which template gets used there? How can we communicate this to users? How does the add template modal scale to accommodate many taxonomies / terms?

In this scenario, if a given post has multiple categories/terms (with custom templates associated with them), an option here could be to automatically list them under the template options for the individual post:

Screen.Recording.2023-03-08.at.18.37.29.mov

Looking forward to hearing your thoughts.

@jameskoster
Copy link
Contributor

Yeah, I guess that's the problem I see here. The motivation is to establish automatic template selection and avoid the tedium of manually applying $custom templates. But if determining which template to use is going to wind up involving user intervention anyway, doesn't that defeat the purpose a bit?

@nefeline
Copy link
Contributor Author

nefeline commented Mar 9, 2023

Yeah, I guess that's the problem I see here. The motivation is to establish automatic template selection and avoid the tedium of manually applying $custom templates. But if determining which template to use is going to wind up involving user intervention anyway, doesn't that defeat the purpose a bit?

I see your point: one way to circumvent this could be to auto-assign the template for whatever category the user added first, minimizing the user manual intervention to only edge cases, where multiple categories/terms have associated templates.

The motivation is to establish automatic template selection and avoid the tedium of manually applying $custom templates.

Avoiding the tedium of manually applying $custom templates is for sure one of the main motivations here, but another one is also to ensure we are not restricting the customization capabilities that WordPress currently supports.

On the PHP side, WordPress already allows extending and modifying the native template hierarchy for a single post via the 'single_template_hierarchy' hook, allowing us to create a template exclusively for posts with a specific category, so it would be essential to support the same via the site editor so site owners and plugin/theme developers can reliably migrate their classic templates to the new FSE experience without requiring manual user intervention.

If not programmatically (have the new template automatically displayed on this modal), at least provide a way for plugin developers to extend it so we can add/remove templates and customize this area, ensuring it is aligned with the extended template hierarchy.

@audunmb
Copy link

audunmb commented Feb 14, 2024

Some of the use cases (like Notes) could probably be better solved with Post Formats as discussed here #53049, but applying some styling by category would still be nice. Different colors in the header, background etc, depending on category would be something I would use at least.

@PascalClaro
Copy link

PascalClaro commented Dec 3, 2024

@jameskoster @nefeline @annezazu hi there! Do you have any news about this feature? I am setting up a pretty complex website using the new Twenty Twenty-Five theme and this would help me a lot shape my overall structure.

@annezazu
Copy link
Contributor

annezazu commented Dec 3, 2024

@PascalClaro there are no further updates here than what you can see above :)

@carolinan
Copy link
Contributor

Even something like adding the taxonomies to the body classes by default would be an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

8 participants