WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


$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.

share|improve this question
Just use the same template, but do the if/else based on the category there. – kaiser Jun 29 '13 at 10:17
up vote 0 down vote accepted

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


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) ) {

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

share|improve this answer
Thank you :) ... – user32447 Jun 30 '13 at 18:34

Your Answer


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.