Support » Plugin: Categories Images » How do i handle image size?

  • Resolved swapnesh


    How do I fetch specific images size from category and sub categories, like thumbnail/large/medium etc something like we use in get_the_post_thumbnail() method, although i tried this option as well but not working..let me know how do i show specific size image.

    This is the code I am using –

    'orderby' => 'name',
    'order' => 'ASC'
    foreach($categories as $subcategory) {
    $subcat_link = get_category_link( $subcategory->term_id );
    echo '<a href="' . get_category_link( $subcategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $subcategory->name ) . '" ' . '>' . $subcategory->name;
    echo '</a>';
    <img src="<?php echo z_taxonomy_image_url($subcategory->term_id); ?>" />
     echo '<p>'. $subcategory->description . '</p>';

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Muhammad


    Hi, currently this plugin supports only one size which you choose from your wordpress media gallery, maybe what you asked for will be available in future update 🙂

    Thx for the reply..seems you were busy with other cool stuffs 🙂

    I was actually building the code as I needed this for my project, let me know if u need it for future version, happy to share my code once done 🙂

    swapnesh, I am very interested in this functionality. Have you made any progress in completing? It’d be great to use add_image_size as we would do for post_thumbnails.

    Thanks and let me know.

    I would also be very interested in this, at the moment I have to rezise the category images multiple times on my webiste and it just doesn’t look very good…

    I found a quick fix for this:
    First, you need to register a new image size with hard crop mode.
    Then, you modify the end of your image url so the cropped image is called (instead of the original image):

    if (function_exists('z_taxonomy_image_url') && z_taxonomy_image_url() !== false) {
    	$img_url = z_taxonomy_image_url();
    	if( strpos($img_url, '.jpg') ){
    		$insert_url = str_replace('.jpg', '-250x180.jpg', $img_url);
    	} elseif (strpos($img_url, '.png') ){
    		$insert_url = str_replace('.png', '-250x180.png', $img_url);
    	echo '<img src="'.$insert_url.'" class="alignleft"/>';

    It is important to set your new image size to hard crop mode so the ‘250×180’ part of the url will work!

    @clairele Thanks for this bit of code. I expanded on it a bit and amde it into a more adaptable function

    function my_get_taxonomy_image_url($catID, $size=false){
        global $_wp_additional_image_sizes;
        if (function_exists('z_taxonomy_image_url') && z_taxonomy_image_url($catID) !== false) {
            $img_url = z_taxonomy_image_url($catID);
            if(empty($img_url)) return false;
            $name = substr( $img_url, 0, strrpos( $img_url, '.' ) );
            $ext = substr ($img_url, strrpos( $img_url, '.' ) + 1 );
                //$size is array of width and height of a predefined image size
                $name .= '-' . $size[0] . 'x' . $size[1];
                //$size is a string of the id of a predefined image size
                $name .= '-' . $_wp_additional_image_sizes[$size]['width'] . 'x' . $_wp_additional_image_sizes[$size]['height'];
            //returns new image url
            return $name . '.' . $ext;

    Now, you don’t have to target jpg/png/gif and you can enter the name of the custom image size or it’s width & height

    So if we did this in functions.php: add_image_size(‘my_cat_thumb’,24,24);

    We can do this in a template file:

    $cats = get_the_category();
    if($cats && is_array($cats)){
        foreach($cats as $cat){
    	echo '<img src="'. my_get_taxonomy_image_url($cat->term_id,'my_cat_thumb') .'" />';

    I would like to add my +1 for this feature. I think it’s very important and it shouldn’t be that hard. All you need to do after the image is loaded, instead of saving the URL, save the media ID. From there developers can go and query the media id (or attachment ID) and get any size they want with wp_get_attachment_image( $attachment_id, $size ). Of course it would be even nicer if you could add a wrapper by extending your z_taxonomy_image_url function like so: z_taxonomy_image_url($cat_id, $size). Hope that makes sense. For now I’m just going to modify your plugin a bit myself, so I wont get any updates, but I’ll check in again soon.

    Hello there,

    after adding the code from danbrellis, I do not get any category image shown and don’t know why… 🙁

    I added danbrellis code to my functions.php.

    In my template I added:

    <?php $cats = get_the_category();
    	if($cats && is_array($cats)){
    		foreach($cats as $cat){
    		echo '<img src="'. my_get_taxonomy_image_url($cat->term_id,'categoryname_thumb') .'" />';

    In my functions.php I added the code-line:

    I uploaded a new image and it just does not show. I also checked if my new image-size (categoryname_thumb,240,240) is created, which also does not happen.

    Is there anything in functions.php that I might have done wrong?

    It would be wonderful if I made a dumb mistake and someone could tell me where and whats wrong… 🙂


    Sorry guys,

    everything works now, I found out that I had made a spelling mistake. 🙂

    Thanks again to danbrellis. And of course to you swapnesh!

    I think it is a great idea to follow Jules Colle advice to make use of wp_get_attachment_image, as far as I understand the wp-codex…


    I think when adding an image size it should be something like:


    for this to work properly.

    Dear All,

    I am suggesting you something you must try, hope you would be able to do what you need here:

    To get original size of image uploaded just follow given steps-

    1. Goto C:\xampp\htdocs\YourProjectName\wp-content\plugins\categories-images
    2. Open categories-images.php file with any editor
    3. Goto line no 149 or search for string “$(“.inline-edit-col .title img”).attr(“src”,thumbs);”

    4. Change “thumbs” to “full”

    5. You are done

    save the file and run your app.

    Hope this will help you out.

    Plugin Author Muhammad


    Hey all,

    Really sorry for my late reply, I was busy the last few months, there will be update so soon with a new features and yes the plugin will support resize images. 🙂

    Keep waiting 😉

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How do i handle image size?’ is closed to new replies.