Download & Extend

Show default images in the view field

Project:Taxonomy Image
Version:6.x-1.x-dev
Component:Views
Category:feature request
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community

Issue Summary

When displaying the term images in a view, if the term in question doesn't have an image set I think that the default image should be displayed as a fallback. This one-liner patch makes that to happen.

AttachmentSize
views_field_default_taxonomy_images.patch417 bytes

Comments

#1

Hello,

You're patch it's eactly what i'm looking for but I can't make it work.

file: views_handler_field_taxonomy_image.inc

I deleted "return;" and replace it by "$tid = $values->tid;" but nothing happens.

Do I have to do something else to make it work? Maybe in my view?

Thanks

#2

interesting... i'm not really sure, I assume that $values->tid is probably empty in your case. I'm unfortunately not too strong at views programming so I'm not really sure what might be going on or where to start looking.

#3

I'm also trying to figure out how to make this work. It seems like it should be the default behavior, or atleast an option in the views field edit form.

#4

Hello hadsie!

if the term in question doesn't have an image set I think that the default image should be displayed

Where do you set the default image?

#5

On the admin/settings/taxonomy_image page there's a "Default image" setting.

#6

Thanks for reply hadsie.
I can't make it work too.
I added the path to the image:
"http://localhost/mysitename/sites/default/files/default.png"
and also i tried to write the relative path to "files" directory:
"default.png"

Then i go to views which is displaying Taxonomy Images.
Clear caches.
And run the view.
And i see that "The Taxonomy Default Image" is not displaying for terms without images.

:(

#7

Patch works for me ok. Tks!

Also found that default image on admin/settings/taxonomy_image is relative to the directory specified in the path to the images field, and doesn't require the full path. The help text is misleading here.

For example, the path to images field in my case is: category_pictures

The default image is specified as: default.jpg

default.jpg is therefore in: sites/default/files/category_pictures/default.jpg

HTH.

#8

I can confirm that the originally supplied patch works successfully with dev. Thanks to Hadsie for a great patch. Saved me a ton of work.

#9

thank you for the patch, i was going crazy thinking that the default image should be showing up.

#10

Status:needs review» reviewed & tested by the community

The patch fixes the problem for me. Tested with Pressflow 6.20.97 and Taxonomy Image 6.x-1.6.

#11

For all folks who was not able to make provided patch to work:

You must add Term ID field along with Term Image field. (This is weird how so many people have same successful results, but no one mentioned the exact view fields setup).

Taxonomy Image stores data in DB only about provided images and retrieval of that data is done through views. Function render($values) does not receive any values ($value is NULL) if there is no DB record in TI table (and for default image there is no record).

So, we have to alter the function to get term id (originally taken from $values->{name_of_the_TI_field}) from another field, which contains term id, in our view.

The suggested patch has alterations
$tid = $values->tid;
but it actually can be
$tid = $values->{the_name_of_your_field_that_contains_tid};

Also I would recommend to use something like

    if (!$tid) {
      if(!$values->tid){
        return; 
      }
      $tid = $values->tid;                     
    }

Hope this will help someone.

#12

The path worked for me, but I did one more thing:

I use the module Taxonomy Image Views Options, so I changed the same line in the same function in the file views_handler_field_taxonomy_image_views_options.inc

And it worked. Thanks!