Page Templates for all kind of post types

This is a rather small change, mostly UI-wise, because most of it is already there, but would help a lot: Using Page Templates for any kind of Post Type, eg. posts or Custom Post Types :slight_smile:


Read-only archive: Issues · ClassicPress/ClassicPress · GitHub

Author: Fabian Wolf

Vote count: 4

Status: open

Tags:

  • difficulty-moderate
  • request-add-feature

No comments posted.

The description is a little sparse.
Post type templates were added in WP 4.7, so I assume it is something in addition to that.
Is it like this ticket #41773 Page Templates // Post Type Templates | Any Post Type?
or more like this ticket #43872 Add page template filter for all post types
or even this ticket #49241 Filter to add post types to custom page templates in get_post_templates()
or something else?

Tagging @fwolf since this is his petition and he’ll be able to elaborate on this.

The literal “Page Template” select option one has got in the WP UI, so indeed similar to #41773 (Page Templates // Post Type Templates | Any Post Type?) – WordPress Trac

A direct use case: Custom Post Type for client site, eg. “Project” or “Referenz”, which is mostly similar as a “normal” page.
Another one straight from a current client project: WooCommerce Product pages - the client got a custom built “Page Template” UI, which essentially fullfils the same role as described. That could have been entirely skipped over with an actual standard, built-in option.

… and so on.

cu, w0lf.

yes, you ARE missing something. You obviously did NOT read the links already mentioned in this thread. Ie. I am NOT talking about using a singular template.

cu, w0lf.

Just want to make sure I’m not misunderstanding. I added a template file to my 2017-child theme:

<?php
/*
Template Name: My Custom Page
Template Post Type: post, page
 */

When I go to create a post, I do see post attributes metabox with a dropdown to select my template:

image

The same goes for custom post types.

Can you elaborate on what exactly is missing from the UI?

You mentioned:

Would you happen to have a screenshot of this UI addition? I think it would help us better understand what it is that this petition wants to add.

I think I have an idea.
It’s not the standard post template that is needed (single.php with sidebar, without etc).
It’s a default template just for custom post types.
Something that the user can the modify.
At present when registering a CPT you need to also prepare a template for that because core doesn’t handle that.
Basically you end up duplicating a template and tweaking it to your likings and then you need to link it to the CPT.
While it’s easy the registering CPT part (just use a generator that gives you the code if you are not a dev), many people aren’t comfortable coding a template from scratch or modifying one, and there’s no easy way around that (plugins doing templates for CPTs need you to understand what you are doing).
This petition (if it is what I am understanding) will lessen the need for templates builders like the beaver builder add on for CPTs and ease the struggles of people who want a CPT template but aren’t able to do it on their own.

Is that what you mean @fwolf?

The requirement is clear from the Ticket that @fwolf linked:

I would like to add a template and have it available to all Post Types.
Perhaps add like this:

/*
Template Name: Full-width layout
Template Post Type: any
*/

So when you want one template for all post types available, instead of doing this:
Template Post Type: post, page, artist, album, track, and-any-other-cpt-you-may-have
you would do this:
Template Post Type: all
or
Template Post Type: any

So instead of creating one template with all CPT names in the Template Post Type header, or many templates with each a CPT in the Template Post Type header, you would have one template with any as value.

I see one issue with this.
There might be actually a CPT named any or even all and making the header possible to hold that value would mean to make that or those words reserved which they are not as of now
So the value used would have to be something that is most likely not already used in some CPT name (because otherwise, the template would apply only to that single CPT and not to all)

Possible values thus could be cp_all_post_types_temlates or whatever complex, probably unique value.

But I am not sure that is such a good idea.
Do you really want your template you may very well use for 100 of your custom post types also on page, posts, and the custom post type the client or user created on his own?
Templates are specific, always, no matter for how many Post Types they are valid, they are and will not be valid for an eventual third post type just because of a single Custom Field, or perhaps no Featured image but your template includes it, and so on.

1 Like

Precisely this. I think this proposal is much more likely to cause confusion than make things easier.

This topic was automatically closed after 2 days. New replies are no longer allowed.