• Resolved evilbeet

    (@evilbeet)


    I’m trying to get Categories associated with my images. I would be fine if these were the same categories associated with its parent post. But, right now, the image.php file has this code:

    This entry was posted on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?> and is filed under <?php the_category(', ') ?>

    But on my image pages, that always results in the category being “Uncategorized,” even when the parent post has a category. Any way to fix this? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • that always results in the category being “Uncategorized,” even when the parent post has a category

    That’s because attachments aren’t filed within categories themselves – only their parent posts are. So you’d need to use something like:

    <?php
    foreach((get_the_category( $post->post_parent )) as $category) {
        echo $category->cat_name . ' ';
    }
    ?>

    instead of <?php the_category;?>

    Thread Starter evilbeet

    (@evilbeet)

    Ooooh that works like a charm!!! I can’t thank you enough!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Linking Images to Categories’ is closed to new replies.