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.
attachment.php
is not the only template file for attachment display. mime-type based template files get priority.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
.I would also suggest
get_template_part
, as in my version of the code, instead of PHP’sinclude
.