I've read through past documentation across this forum regarding taxonomy images and views however the solutions posted no longer seem to work (for me anyway).
I'm completely open to use whichever taxonomy image plugin is going to work.
I have a View setup to display a list of entries for a custom taxonomy within a custom post type (both setup using Types). The output within views is a loop so whatever code is being used to grab the relevant taxonomy image must function within that loop.
Anyone got any ideas?
Dear Grant,
I have had more requests for the following plugin so I know it better:
http://wordpress.org/plugins/taxonomy-images/
With this plugin installed and enabled, you can configure any taxonomy to have an image associated.
Add these lines to functions.php in your theme to add the shortcode we need:
add_shortcode('wpv-post-taxonomy-image', 'taximage');
function taximage($atts) {
return apply_filters( 'taxonomy-images-list-the-terms', '', array( 'taxonomy' => $atts['type'], 'post_id' => get_the_ID() ) );
}
Then in your Views you can insert a shortcode like this to display the image associated to a taxonomy:
[wpv-post-taxonomy-image type="sector"]
Replace "sector" with the slug of your custom taxonomy.
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Hi Caridad,
Here is what I have:
View:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%">
<wpv-loop wrap="3" pad="true">
[wpv-item index=1]
<tr><td>[wpv-taxonomy-link][wpv-post-taxonomy-image type="brewery"] </td>
[wpv-item index=other]
<td>[wpv-taxonomy-link][wpv-post-taxonomy-image type="brewery"] </td>
[wpv-item index=3]
<td>[wpv-taxonomy-link][wpv-post-taxonomy-image type="brewery"] </td></tr>
[wpv-item index=pad]
<td></td>
[wpv-item index=pad-last]
<td></td></tr>
</wpv-loop>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]<strong>No items found</strong>[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
functions.php
add_shortcode('wpv-post-taxonomy-image', 'taximage');
function taximage($atts) {
return apply_filters( 'taxonomy-images-list-the-terms', '', array( 'taxonomy' => $atts['type'], 'post_id' => get_the_ID() ) );
}
Output Page: hidden link
Taxonomy Slug is brewery
As you can see there are still no images loaded on the page.
Dear Grant,
I tested this before posting, with latest versions of everything. Can you check that you are actually listing posts and not terms?
Regards,
Caridad
My post type structure is:
Posts: Beer
Taxonomys: Brewery, Styles, Country
I want to output all the different brewery's with their respective taxonomy images. I don't see how that's possible by changing from taxonomy to posts within the view? Won't that output the beer posts instead?
Dear Grant,
I thought you wanted posts (beer) in your first post, now I realize you need a taxonomy view (brewery). I will post back shorty with new code to accomplish this.
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Dear Grant,
In this case, the code for the shortcode is a bit different. I will name it wpv-taxonomy-image to avoid confusion with the previous one:
add_shortcode('wpv-taxonomy-image', 'taximage');
function taximage($atts) {
global $WP_Views, $wp_query;
$term = $WP_Views ->get_current_taxonomy_term();
$wp_query->queried_object = $term;
return apply_filters( 'taxonomy-images-queried-term-image', '' );
}
This one needs no parameters, use it like this in your View layout:
[wpv-taxonomy-link]<br />[wpv-taxonomy-image]
Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Caridad
Great! That's working and pulling up the images. I'm assuming I can just tweak the image display settings by following the documentation for the taxonomy image plugin.
For anyone looking for an update to this code there is a solution posted here: https://toolset.com/forums/topic/taxonomyterm-images-question/. The problem with this code is that it does not rest wp_query - this will cause problems with certain aspects of the page. Here is the updated code that you should be using:
add_shortcode('wpv-taxonomy-image', 'taximage');
function taximage($atts) {
global $WP_Views, $wp_query;
$term = $WP_Views ->get_current_taxonomy_term();
$wp_query->queried_object = $term;
$filtered = apply_filters( 'taxonomy-images-queried-term-image', '' );
$wp_query->queried_object = wp_reset_query(); // restore the original wp_query
return $filtered;
}
Does this still work? I can't get any results for me. How do you specify which taxonomy you want to call? I have multiple.
Adding request for follow up emails.