• Resolved c-m

    (@c-m)


    I’m using the categories-images plugin and am trying to display the sub categories of a particular category.

    I don’t want to display the posts, just the sub category title, description and image.

    Here’s what I’ve got so far:

    <?php
    $args = array('child_of' => 67);
    $categories = get_categories( $args );
    foreach($categories as $category) {
    	echo '<li>';
    	 the_post_thumbnail();
    	echo '<div class="post-details-wrapper">';
        echo '<h3><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h3> ';
        echo '<p>'. $category->description . '</p>';
       	echo '</div>';
        echo '</li>';
    }
    ?>

    Rather than displaying the featured-image of each sub-category being listed, all I’m getting is the same image from one particular post(not even the main parent category image). Even though I’m not showing any posts on the page, only categories.

    Any ideas?

    Thanks

    https://wordpress.org/plugins/categories-images/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter c-m

    (@c-m)

    I’ve made some progress with this using:

    <?php
    $args = array('child_of' => 67);
    $categories = get_categories( $args );
    foreach($categories as $cat) {
    	echo '<li>';
    	echo '<img src="' . z_taxonomy_image_url($cat->term_id). '"/>';
    	echo '<div class="post-details-wrapper">';
        echo '<h3><a href="' . get_category_link($cat->term_id) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $cat->cat_name.'</a> </h3> ';
        echo '<p>'. $cat->description . '</p>';
       	echo '</div>';
        echo '</li>';
    }
    ?>

    It probably needs tidying up though, and I need to somehow resize the images.

    Plugin Author Zahlan

    (@elzahlan)

    Hey c-m

    I think your second code is fine, and to use resizing you can do as following:
    z_taxonomy_image_url($cat->term_id, 'medium')
    or change medium to any other size like (thumbnail, medium, large, or full) or even you can use specific size, for example:
    z_taxonomy_image_url($cat->term_id, array(500, 300))

    The plugin uses the default wordpress resizing so if you need more info about resizing please check here

    Hope I helped

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Displaying sub-category images’ is closed to new replies.