WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#12759 closed defect (bug) (fixed)

"Template" shouldn't show for custom hierarchical post types

Reported by: greenshady Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:

Description

When creating a custom post type that is hierarchical, the post type would likely support the page-attributes meta box because this grants access to the parent drop-down.

While I can certainly see the benefit in having the ability to create custom templates, my "page" templates shouldn't appear for other post types. These templates were created for use specifically with the page post type.

I see four solutions for fixing this issue:

1) Remove this when the post type isn't a page.

2) Allow for specific post type templates to be recognized in the form of:

$post_type->singular_label Template: Example

3) Create a separate meta box that simply handles the parent so the page-attributes meta box isn't needed.

4) Add a hook so developers can remove this.

Note that the page template drop-down is also shown with the quick edit feature.

Attachments (1)

meta-boxes-template-dropdown.diff (727 bytes) - added by greenshady 4 years ago.
Don't show the template dropdown for non-page post types.

Download all attachments as: .zip

Change History (11)

greenshady4 years ago

Don't show the template dropdown for non-page post types.

comment:1 greenshady4 years ago

  • Keywords has-patch added

comment:2 greenshady4 years ago

As an extra note to this: Even if a "page" template is shown for non-page post types, it is neither saved nor used.

comment:3 ryan4 years ago

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

(In [14642]) Show page template dropdown only for pages and not for other post types. Props greenshady. fixes #12759

comment:4 sarah_hines4 years ago

Is this logic still valid w/ 3.0? Or rather, should custom post types be completely restricted to just one page template? CPT can function as pages (all the capabilities are there) so why shouldn't a cpt be able to have page-by-page templates?

comment:5 sarah_hines4 years ago

  • Cc sarah_hines added

comment:6 greenshady4 years ago

Is this logic still valid w/ 3.0?

This ticket and bug fix were made specifically for 3.0.

Or rather, should custom post types be completely restricted to just one page template? CPT can function as pages (all the capabilities are there) so why shouldn't a cpt be able to have page-by-page templates?

Custom post types should not use templates created for a different post type.

comment:7 elementweb3 years ago

  • Cc elementweb added
  • Resolution fixed deleted
  • Status changed from closed to reopened

This seems a poor solution, as custom templates do not have to be reserved for page types. Before custom post types, they were indeed only used for page types, but that is only a matter of what the post type supports.

If a post type (whether by default, as for pages, or custom) supports page-attributes, there is no reason it should not allow for custom templates to be selected. Doing so basically tells the post type to behave like a page, and as such it should have all the functionality of a page.

This restricts functionality for the whole platform out of the personal preference of one or a few persons. It also contradicts the documentation (which should either be adjusted to reflect this decision, if the current proposal is deemed unacceptable).

It would be best to allow custom templates to be used when a post type has page attributes (so as not to arbitrarily restrict functionality) until a better choice is made, for example the addition of a restriction for custom templates.

Custom post types should not use templates created for a different post type.

This is particularly wrong as custom templates are not created specifically for pages, there is no such distinction other than the fact that before custom post types, it was their only use. Custom post types have changed this paradigm.

A rather "easy" fix would be to add an optional attribute to custom templates that either limits or restricts post types (by default either to "page" post type or to all). Although I do note that there are several changes necessary for this as page attributes are set to be saved in several places only for the "page" post type.

I have found that there are 2 distinct places to patch to allow the page template to be save, but there are other places to check as the meta box does not reload the selected page template (even though correctly saved in postmeta) and the page template is not loaded. Basically is_page() would come down to checking whether the post type supports page-attributes.

comment:8 aaroncampbell3 years ago

I'm not sure why a custom template should only be available for pages. Most themes offer custom templates for things like "full width", "right sidebar", "three column", etc. Why wouldn't these be useful on certain post types?

I'd prefer to see an option added to custom post types that allows them to use custom templates. However, for now I'd either like to see [14642] or this ticket punted to early 3.2...let's get 3.1 out the door :)

comment:9 aaroncampbell3 years ago

  • Cc aaroncampbell added

comment:10 nacin3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

This ticket was closed on a completed milestone. New ticket, please.

Note: See TracTickets for help on using tickets.