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:
- text.php
- plain.php
- 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
.