Post formats “audio” and “video” only showing in index.php

I have files in my theme called single-audio.php and single video.php, but when I click on an audio post-format or video post-format wordpress uses the index.php instead of my single-audio.php or single-video.php files. Any ideas?

Related posts

Leave a Reply

3 comments

  1. There is a huge difference between Post Formats and Post Types. I am assuming you are using post formats, which do not have a default template file for you to use.

    What you can do though is use has_post_format() to see if the post has the format you are using, and if it does, use get_template_part() to get a specific template file that you created to display there.

    For example:

    // If this post has a post format of 'video'
    if( has_post_format( 'video', $post->ID ) ) {
    
        // Then get and display 'single-video.php'
        get_template_part( 'single', 'video' );
    
    }
    
  2. If you really want to use single files for each post-format type you could try something like this: (paste to functions.php)

    function post_format_template() {
    global $post;
    $format = get_post_format($post->ID);
    if ( is_single() && $format ) {
            include('single-format-'.$format.'.php');
            exit;
        }
    }
    add_action('template_redirect', 'post_format_template',10);
    

    It’s a possible solution, but I wouldn’t recommend it, as long as you’re not 100% sure about what you’re doing resp. what is happening here.

    Jared response is the recommended way of dealing with post-formats.

  3. If I understand your question correctly, you would need to do the following:

    1. Add a new page via the Dashboard
    2. Give that new page a name like “Audio post format” and associate that page to a template. There is a selectbox which would allow you to select a template.

    HTH