I am using this function to display categories specified to a post having gallery on the image attachment page.
<p>CATEGORY: <?php the_category(', '); ?></p>
The problem is that this function doesn’t return anything. I have also used this way to display categories but no success:
<?php $categories = get_the_category();
$separator = ', ';
$output = '';
if($categories){ ?>
<span>CATERGORY:</span>
<?php foreach($categories as $category) {
$output .= '<a href="'.get_category_link($category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
}
echo trim($output, $separator);
}
?>
Can anyone tell where problem lies???
Thanks
If you have WordPress 3.5 this will work.
http://make.wordpress.org/core/2012/12/12/attachment-editing-now-with-full-post-edit-ui/
First you need to enable this in your theme, Put this in your functions.php file in your theme root.
In your image.php or attachments.php file add:
Then go and add some categories to a attachment.
See the question / answer on this link.
The answer have 2 different solutions, easy with default categories and taxonomies and also a solution with custom taxonomies only for media.