Opened 12 years ago
Closed 7 months ago
#27425 closed enhancement (invalid)
Templates For Posts Formats
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Post Formats | Keywords: | |
| Focuses: | template | Cc: |
Description
If I opt to use Custom Post Templates, then I can easily put a custom post template by putting a file named single-[name of the custom post], but that same feature is not available for the post formats.
I love the post format feature in WordPress, and people just don't want to use that for some reasons, but this would really attract some of the audience to use the post formats.
For example, a post with Audio format will first look for single-audio.php or single-audioformat.php or anything cuz it single-audio.php may effect the Audio Custom post type.
What do you guys think of this idea?
Change History (8)
#2
follow-up:
↓ 3
@
12 years ago
A workaround:
function use_post_format_templates_27425( $template ) {
if ( is_single() && has_post_format() ) {
$post_format_template = locate_template( 'single-' . get_post_format() . '.php' );
if ( $post_format_template ) {
$template = $post_format_template;
}
}
return $template;
}
add_filter( 'template_include', 'use_post_format_templates_27425' );
#3
in reply to:
↑ 2
@
12 years ago
Replying to SergeyBiryukov:
A workaround:
function use_post_format_templates_27425( $template ) { if ( is_single() && has_post_format() ) { $post_format_template = locate_template( 'single-' . get_post_format() . '.php' ); if ( $post_format_template ) { $template = $post_format_template; } } return $template; } add_filter( 'template_include', 'use_post_format_templates_27425' );
I know this trick, but a feature like this should be in the core. I love formats option & people do some great stuff with it.
#7
@
9 months ago
- Keywords close added
Hey Everyone,
I have just taken a look at this, as it appears this ticket has been sitting for the last decade without much movement. This ticket proposes a significant change to the WordPress template hierarchy by introducing dedicated template files for post formats (e.g., single-quote.php).
As mentioned by @SergeyBiryukov there is a filter you can add to your theme to implement the file based method as initially suggested. Seeing as you need to add support to your theme to include these in the first place, it makes sense that if you wanted to add post formats to your theme, then in the same place you could extend the templates if you wanted/needed too.
Secondary to this the recommended approach is to use get_template_part() in conjunction with get_post_format(). For example, a theme can include get_template_part( 'content', get_post_format() ) within single.php or archive.php, allowing it to load content-quote.php, content-gallery.php, etc., based on the post's format.
Because both of these methods give ample customization for theme developers without adding further complexity to the core template loading process, implementing new template files for post formats in core feels somewhat unnecessary as existing solutions suffice. As of such I am going to mark this ticket with the close tag, but please feel free to continue the conversation around this request further if you disagree with my assessment. 😃
#8
@
7 months ago
- Keywords dev-feedback needs-patch close removed
- Resolution set to invalid
- Status changed from new to closed
Hi all, given that it's possible to do this with existing functionality, I'm going to close this ticket to help clean up Trac. See examples of this in the Twenty Eleven/Twelve/Thirteen/Fourteen/Fifteen/Sixteen/Seventeen/Twenty One themes.
Anyone looking forward to review this ticket of mine?