0

I've searched everywhere and tried a couple plugins with no success. I'm using WP 3.9.1.

I have to create different ways to show my posts. If they are "standard" they use the single-post.php. That's ok.

If they have an image gallery, I want to change the whole structure. Same thing if they contain a video. I want to change the html structure.

So, instead of creating different custom post types, a thing that creates other problems down the line to take care of, I just want to be able to say to wp "hey, use this template file".

How can I be able to do that? I guess it's about making wp asking the editor "for this post, what template you want to use?" in admin.

5
  • 1
    Have you tried using post formats? codex.wordpress.org/Post_Formats Jul 4, 2014 at 10:56
  • I tried. I added add_theme_support( 'post-formats', array( 'photopost', 'videopost' ) ); in functions.php. I also added add_post_type_support( 'photopost', 'post-formats' ); add_post_type_support( 'videopost', 'post-formats' ); in functions.php. The post edit page show a "format" section, but it only has "standard" as option. Jul 4, 2014 at 11:05
  • Oh, and I also created a photopost-template.php and videopost-template.php files. Both with their own /* Template Name: [..] */ Jul 4, 2014 at 11:12
  • Oooooooh now I get it. There is no such thing as custom post formats, is it? Jul 4, 2014 at 11:20
  • 1
    Go and see how the bundled themes make use of post formats. I suggest that you activate twentyfourteen on a local install and play arount with post formats which is activated by default in the twentyfourteen theme Jul 4, 2014 at 11:52

1 Answer 1

2

Use below code for getting post format, simple made condition if post format ="standard" then load your preferred template

 $format = get_post_format();
if($format ="video")
{
get_template_part( 'format', $format );
}

Something like this.

1
  • With something like that I made it work. Inside the single-post.php file i put that kind of conditions after the loop. Something like: if ( has_post_format( 'video' )) { //put the html/php for the video format } elseif ( has_post_format('gallery')) { // put the html/php for the gallery format } else { //put the html/php for the standard post format } Jul 4, 2014 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.