Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
if those are template files, you would need to associate them to a page. A page uses index.php as the default template file. –  rexposadas Jan 30 '12 at 22:54
    
thanks how do I associate them? –  James Jan 30 '12 at 22:58
    
single-audio.php would be a single post in a post type called audio, not a post format. –  Jared Jan 30 '12 at 23:02
    
and a page uses page.php as the default template file, index.php is a fallback. –  ungestaltbar Jan 30 '12 at 23:08
1  
@Jared you should post that as an answer (ideally, along with an example get_template_part() call for including post format-specific content). –  Chip Bennett Jan 31 '12 at 2:26
show 1 more comment

3 Answers 3

up vote 5 down vote accepted

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' );

}
share|improve this answer
    
Thanks for your time, much appreciated. –  James Jan 31 '12 at 8:20
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
Thanks. According to the wordpress Template Hierarchy when displaying a post it should look for single-$posttype.php then single.php then index.php I can't undersatnd if I have a single-audio.php file why its not using that? –  James Jan 30 '12 at 23:30
    
because you're using post-formats, not post-types. post formats don't have a dedicated template file. –  ungestaltbar Jan 31 '12 at 5:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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