0

I want to use post types to style video posts differently. This should be quite easily achieved with custom post types.

But I only want the video post type to affect the post when it is in "single".

In other words I want the front page to stay as it is but when a video post is clicked on (and single.php is rendered) I want it to be styled differently than regular posts.

How can I achieve this?

I have read a dozen articles about custom post types, but all of them explain how to render CPT on the front page, which is not what I need.

Functions.php

add_theme_support( 'post-formats', array(
    'aside',
    'gallery',
    'image',
    'link',
    'video',
    'quote',
    'link',
    'video',
    'status', 
    'audio', 
    'chat'
) );

I am using _s for theme development so inside the theme root folder I have a folder called template-parts with content-none.php content-page.php content-search.php content-single.php content.php and single-video.php

4
  • Woah - do you actually mean custom post type, or are you referring to a post with the format "video"? Commented Apr 25, 2016 at 14:44
  • Sorry, I was indeed referring to the "standard" post format. I will edit my question accordingly.
    – Arete
    Commented Apr 25, 2016 at 14:45
  • I think I fixed it by renaming single.video.php to content-single-video.php. This is because of the hierarchy of files that _s generates.
    – Arete
    Commented Apr 25, 2016 at 15:03
  • Yeah, you gotta be careful with your terminology - custom post types are something completely different! Commented Apr 25, 2016 at 15:04

2 Answers 2

0

Just use the single-{post-type}.php template, as described in the Template Hierarchy.

3
  • I have read the whole article and dozen others. It does not explain how to do this practically. The documentation merely states that it is possible.
    – Arete
    Commented Apr 25, 2016 at 14:16
  • Have you tried creating a single-{name-of-your-custom-post-type}.php in your theme folder? Commented Apr 25, 2016 at 14:17
  • I have but nothing happens..
    – Arete
    Commented Apr 25, 2016 at 14:22
0

single.php file or custom single-{post_type}.php

<?php 

while ( have_posts() ) : the_post();
  get_template_part( 'content', get_post_format() );
endwhile;

make a new template file content-video.php customize video format post.

When you add post format to custom post type add support in your function.php add_post_type_support( 'post_type_name', 'post-formats' );

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.