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.

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

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

share|improve this question
1  
Just use the same template, but do the if/else based on the category there. –  kaiser Jun 29 '13 at 10:17
add comment

1 Answer

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

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.

share|improve this answer
    
Thank you :) ... –  user32447 Jun 30 '13 at 18:34
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.