Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've written a patch against this module that allows users to select a view to use for setting images for a taxonomy term. My use case for this is image galleries, and allowing the users to set the default image using a cck field on the node and filter on that field.
It depends on the embed_views module.
Below are also instructions for how to create a view to use with taxonomy image:
Step 0: Install the <a href="http://drupal.org/project/embed_views">embed_views</a> module.
Step 1: Create a new view of view type 'node'
Step 2: Set the following settings on the view
Style: Unformatted
Row style: Fields
Items to display: 1
Use pager: No
More link: No
Step 3: Add a field to the view - note that this field should be the image to be displayed as the term image.
Select the format 'Path to File'.
Set the label = None.
There should only be a single display field in this view, if you need to add other fields for whatever reason, set their "Exclude from display" flag
Step 4: Add the filters you need
You'll probably want to add a filter on the "Taxonomy: Vocabulary" as well.
Step 5: Add an argument 'Taxonomy: Term ID'
Step 6: Add a new display of type "Embed" and save the view.
Step 7: Configure taxonomy image
In site configuration -> taxonomy image check the box 'Use a view to select the term images' then select the view you just created.
You may need to clear your cache for the images to show up.
Comment | File | Size | Author |
---|---|---|---|
#1 | taxonomy_image_638578.patch | 3.91 KB | hadsie |
taxonomy_image_views_image.patch | 3.9 KB | hadsie |
Comments
Comment #1
hadsie CreditAttribution: hadsie commentedI noticed a minor issue in the patch. Here's the new version.
Comment #2
shaiss CreditAttribution: shaiss commentedThank you for the how to. I folowed everything and applied the patch. How are you using your newly created view?
Comment #3
hadsie CreditAttribution: hadsie commentedBasically I'm using taxonomy image to make photo galleries. A user can select a photo in the gallery (i.e. term) to be the main gallery image (i.e. the image chosen for the taxonomy image term). I then have a view that filters on all images in that particular term sorted by the sticky bit and limits the results to just 1 value. That's the view for the taxonomy image selection and it's been working relatively well for me.
Comment #4
freddyseubert CreditAttribution: freddyseubert commentedFirst off, thanks for patch and description. I also want to display image galleries based on taxonomy, tax. images and tax. list.
Now I have one big problem:
I created the view according to your description and configured the module Taxonomy Image to use the output from that view. But if I browse to my gallery list, there are no images displayed.
I'll post you some more information and hope, that you can give me a hint what to do:
Drupal 6.16
Taxonomy Image 6.x-1.x-dev (2009-May-02)
Taxonomy List 6.x-1.3
The export of the view generating the image path:
Is it possible, that the module has changed since you created the patch above, even if the patch applied cleanly?
*UPDATE:
Here's the generated HTML in my case:
<div class="taxonomy-list-item taxonomy-list-term-37"><ul class="links"><li class="taxonomy-list-image first last"><a href="/wissensmanagement/bildergalerien/berlin"></a></li></ul><a name="37"></a><a href="/wissensmanagement/taxonomy/term/37/all" class="taxonomy-list-term">Berlin</a><div class="taxonomy-list-term-count">(6)</div></div></td>
And in addition to that I should say, that the images are displayed correctly by assigning them directly to a term (without using a view).
Thanks in advance, Freddy
Comment #5
hadsie CreditAttribution: hadsie commentedI think you'll need to flush caches in order for the image to be refreshed. That could be the problem.
Comment #6
freddyseubert CreditAttribution: freddyseubert commentedWow, thanks for such a quick reply! I've deactivated caching on my testsystem and in addition flushed the caches all the way... Any other possible way to get this working?
Comment #7
freddyseubert CreditAttribution: freddyseubert commentedAh, now I know, why it didn't work. After patching the file taxonomy_image.module, line 256 reads
$result = preg_replace('/Export|Edit|Clone/', '', $result);
But if you are running a localized system (in my case German) the admin links of views are no longer called "Export", "Edit" or "Clone". So I commented out this line and added the now localized links.
Now it works like a charm - thanks for your support anyway!
I thought, I'd post this workaround here for other people, who want to use your patch together with a localized views-module. But if there is a way to pull the localized strings out of the db instead of hardcoding them to the module file, this would be even better :)
Comment #8
hadsie CreditAttribution: hadsie commentedhmmm... yeah. I guess the regex should be built using t() in that patch instead. that particular part is pretty ugly as well. and I wonder if there's a way to get rid of it altogether.