Forums

[resolved] Linking Images to Categories (3 posts)

  1. evilbeet
    Member
    Posted 2 years ago #

    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!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  3. evilbeet
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic