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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tgiokdi

    (@tgiokdi)

    from what I’ve found on the internets, apparently the category is NOT updated for attachments. anyone know how to update those categories? or even see them? I found that I can go through mysql and update them manually in the wp_term_relationships table, but there are thousands upon thousands of posts that need to be corrected.

    Thread Starter tgiokdi

    (@tgiokdi)

    anyone know how to update the attachment categories?

    Thread Starter tgiokdi

    (@tgiokdi)

    somehow, the other post that I had going about this was closed, if a mod could look into reopening that one, I would appreciate it.

    Thread Starter tgiokdi

    (@tgiokdi)

    oh man, 3 months and two wordpress updates and the attachment.php theme file is still broken?

    in fact, it seems like it’s even more broken now, with posts that were working fine before now returning the incorrect crap on them.

    does anyone know how to show content on the attachment page based on what the parent post’s category is?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘attachment.php category if/else statements’ is closed to new replies.