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

  1. Sebastian Starke
    Posted 3 years 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.


  2. Eddie Moya
    Plugin Author

    Posted 3 years 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 Starke
    Posted 3 years 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;

    Thanks for your reply!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Media Categories
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic