attachment.php category if/else statements
-
ok, here’s my situation. Google’s told me that I need to not have their ads on NSFW content, which I’m perfectly happy with. My problem is that the attachment.php file doesn’t seems to be able to tell what category the attachment is in. I did some googling and found a previous wordpress support thread that mentioned using this:
‘<?php
$post = get_post($ID);if ( is_object($post) ) :
if ( (‘attachment’ == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) ) :
setup_postdata($post->post_parent);
if ( in_category(‘images’) ) { echo “THIS IMAGE IS SAFE FOR WORK”; }
else { include “header-advert-nsfw.php”; };endif;
endif;
?>’for the intent of this post, my blog only has two categories, NSFW and Images.
now, this works, but only for some posts, and it’s driving me crazy as to why it works on some and not others. from what I can tell, if the post was originally in the Images category and I edited it to be in the NSFW category, the code above will still think that it’s in the Images category, and not the NSFW one. I’ve tried looking into the category tables in the database, but I can’t make heads or tails of it.
Anyone know what’s going on here? why isn’t the category being changed where this code can see it? is there alternate code that will work better with the current category database layout?
- The topic ‘attachment.php category if/else statements’ is closed to new replies.