Skip Navigation

[Gelöst] Including a taxonomy image in a view

This support ticket is created vor 9 Jahre, 10 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 10 Antworten, has 4 Stimmen.

Last updated by DavidAlexander vor 9 Jahre, 10 Monate.

Assigned support staff: Caridad.

Author
Artikel
#160351

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?

#160527

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

#160534

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.

#161368

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

#161536

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?

#161780

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

#161795

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

#162220

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.

#232507

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;
}
#457015

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.

#457030

Adding request for follow up emails.