WordPress.org

Ready to get started?Download WordPress

Forums

Media Categories
[resolved] get category in image.php (3 posts)

  1. Sebastian
    Member
    Posted 1 year ago #

    How can I get the category of the current image from inside image.php? In category.php I can use $cat for my query, but in image.php that returns every image, not just the images from the category of the current image.

    http://wordpress.org/extend/plugins/media-categories-2/

  2. Eddie Moya
    Member
    Plugin Author

    Posted 1 year ago #

    Im not sure what image.php is. Is it simply part if the theme your using? Or is it part of the template hierarchy that Im not familiar with?

    Attachments are a post type like any other. So generally speaking anything that shows a list of images is going to have some sort of loop. All you need to do is have the id for that image, and pass it to a function like wp_get_object_terms().

    In the case of single image templates, that too should have access to the images ID. The same applies.

  3. Sebastian
    Member
    Posted 1 year ago #

    It is part of the 2012-Theme, it is the template for viewing an attachment. I already solved this yesterday and came to the same sollution:

    <?php $terms = get_the_terms( $post->ID , 'category' );
    foreach( $terms as $term ) {
    $cat = $term->name;
    unset($term);
    }?>

    Thanks for your reply!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic