$args = array('parent' => 17);
$categories = get_categories( $args );
foreach($categories as $category) { 
    echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    echo '<p> Description:'. $category->description . '</p>';
    echo '<p> Post Count: '. $category->count . '</p>';  

from the above code i got the subcategories also i want to display images for subcategories with hyperlink and the above code does not show empty category. help me in this.

1 Answer 1


Wordpress taxonomies (Categories and Tags) do not have featured images, so there is nothing 'standard' that you can use. Therefore you need to customise your code to suit by using Custom Fields to extend the taxonomy to include an image.

However, manually coding this becomes somewhat more complicated when using Images from your media library so you may find it more convenient to use a plugin to create and manage these custom fields for you. In the link above, you will see three plugins listed at the bottom of the page. I only have experience of Advanced Custom Fields but using that plugin I have added Images to Categories and output them as per your example, so its definitely possible. There are plenty of help pages to assist you with this.

As for showing the empty categories, thats simply a case of adding an extra argument to your get_categories function, like this:

$args = array('parent' => 17,'hide_empty' => false);
$categories = get_categories( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.