creating a second image attachment template?

Hi i am trying to create a second image attachment template. I have one, but I have created another. In the second one I want the attachments that are under a certain category of a post to have a different view from the rest.

Here is what i have in the nomrmal photo attachment page to try to call the category

Read More
<?php

$post = $wp_query->post;

if ( in_category('4679') ) {

include(TEMPLATEPATH . '/bet-photo.php'); 

?>

but the problem is, It’s still showing the old attachment page and not the new one. What am i doing wrong.

Related posts

1 comment

  1. attachment.php is not the only template file for attachment display. mime-type based template files get priority.

    • MIME_type.php – it can be any MIME type (image.php, video.php,
      application.php). For text/plain, in order:

      1. text.php
      2. plain.php
      3. text_plain.php

    http://codex.wordpress.org/Template_Hierarchy#Attachment_display

    I expect that that is the issue you are seeing. Check your theme for image.php.

    There is a further problem with your code. Attachments don’t have categories as far as I know. The category is inherited from the parent post. That means that you will need to pass the parent post ID to in_category.

    if ( in_category('2', $post->post_parent) ) {
       get_template_part('bet-photo'); 
    }
    

    I would also suggest get_template_part, as in my version of the code, instead of PHP’s include.

Comments are closed.