Skip Navigation

[Résolu] Tried everything suggested in the forum about Taxonomy Images without success !

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.

This topic contains 18 réponses, has 2 voix.

Last updated by SD Il y a 8 années et 3 mois.

Assigned support staff: Caridad.

Auteur
Publications
#104881

SD

Hi there, first of all i would like to let you know that i have tried everything suggested in the forum before disturb you guys, but i'm 5 days away from the delivery of this project so after 2 days i cannot afford just keep trying by myself since my PHP knowledge is pretty limited.

What i'm trying to do is assign an image/thumb to each term under my custom taxonomy(slug = venture-type) so as suggested in other threads of the forum i installed "Taxonomy Images" plugin (just to be exact this is the one i'm talking about http://wordpress.org/plugins/taxonomy-images/ ) and then added the shortcode in my functions.php in order to be used inside Views.

Here is my Views Meta HTML:

[wpv-layout-start]
<!-- wpv-loop-start -->
   <div id="emotions-table">
   <table width="100%">
      <wpv-loop wrap="5" pad="true">
         [wpv-item index=1]
        <tr><td><a href="[wpv-taxonomy-url]" title="[wpv-taxonomy-title]"><img src="[taximage]" alt="[wpv-taxonomy-title]" title="[wpv-taxonomy-title]" width="175" height="250" align="left" class="emotion-thumb"/><div id="emotion-name">[wpv-taxonomy-description]</div></a></td>
         [wpv-item index=other]
          <td><a href="[wpv-taxonomy-url]" title="[wpv-taxonomy-title]"><img src="[taximage]" alt="[wpv-taxonomy-title]" title="[wpv-taxonomy-title]" width="175" height="250" align="left" class="emotion-thumb"/><div id="emotion-name">[wpv-taxonomy-description]</div></a></td>
         [wpv-item index=5]
          <td><a href="[wpv-taxonomy-url]" title="[wpv-taxonomy-title]"><img src="[taximage]" alt="[wpv-taxonomy-title]" title="[wpv-taxonomy-title]" width="175" height="250" align="left" class="emotion-thumb"/><div id="emotion-name">[wpv-taxonomy-description]</div></a></td></tr>
         [wpv-item index=pad]
            <td></td>
         [wpv-item index=pad-last]
            <td></td></tr>
      </wpv-loop>
   </table>
</div>
<!-- wpv-loop-end -->
[wpv-no-taxonomy-found][wpml-string context="wpv-views"]<strong>No taxonomy found</strong>[/wpml-string][/wpv-no-taxonomy-found]
[wpv-layout-end]

And this is how it renders(BEFORE ADDING THE SHORTCODE TO FUNCTIONS.PHP): hidden link

Until now everything looks as expected since the shortcode is not added to functions.php yet.

The next step is to add the shortcode to my functions.php in order to render the URL of the image instead of [taximage] word.

This is what i tried at first:

add_shortcode('taximage', 'taximage');
function taximage() {
global $post;
return apply_filters( 'taxonomy-images-queried-term-image-url', '', array('post_id' => $post->ID, 'taxonomy' => 'venture-type') );
}

And this is how it renders: hidden link as you can see the word [taximage] disappears but nothing else happen it returns blank without any url.

I have also tried the below tweaks(as i said my PHP is limited so i'm tweaking to find a solution to this) but the same result as above:

add_shortcode('taximage', 'taximage');
function taximage() {
return apply_filters( 'taxonomy-images-queried-term-image-url', '', array('taxonomy' => 'venture-type') );
}

1st Tweak:

add_shortcode('taximage', 'taximage');
function taximage() {
return apply_filters( 'taxonomy-images-queried-term-image-url', '' );
}

2nd Tweak:

$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
add_shortcode('taximage', 'taximage');
function taximage() {
return $image_url;
}

3rd Tweak:

$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
add_shortcode('taximage', 'taximage');
function taximage() {
print $image_url;
}

As already said all the above return the same result: hidden link

One more time sorry for disturbing you with this since it involves a third party plugin but i saw in the forum that CaridadZ and some other support members are pretty good with this and i'm kind of screwed here because i need to have this ready urgently.

Thanks in advance,
Stelios

#105333

Dear Stelios,

There are several version of the taximage shortcode around the forum and that can be confusing. The one you need is probably:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
        $associations = get_option( 'taxonomy_image_plugin' );
        $term = get_term_by('slug', $atts['slug'], $atts['type']);
        if ( !empty($term) && isset( $associations[ $term->term_taxonomy_id ] ) ) {
                $attachment_id = (int) $associations[ $term->term_taxonomy_id ];
                $img = taxonomy_image_plugin_get_image_src( $attachment_id );
                return '<img src="' . $img . '" />';
        }
}

To use it do the following:

[taximage type="venture-type" slug="[wpv-taxonomy-slug]"]

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

#105341

SD

Hi Caridad, thanks for taking the time to help me.

Unfortunately ti still render the same...it is showing nothing.

As you suggested i use this code for adding the shortcode:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
        $associations = get_option( 'taxonomy_image_plugin' );
        $term = get_term_by('slug', $atts['slug'], $atts['type']);
        if ( !empty($term) && isset( $associations[ $term->term_taxonomy_id ] ) ) {
                $attachment_id = (int) $associations[ $term->term_taxonomy_id ];
                $img = taxonomy_image_plugin_get_image_src( $attachment_id );
                return '<img src="' . $img . '" />';
        }
}

And here is my code inside the view:

[wpv-layout-start]
<!-- wpv-loop-start -->
   <div id="emotions-table">
   <table width="100%">
      <wpv-loop wrap="5" pad="true">
         [wpv-item index=1]
        <tr><td><a href="[wpv-taxonomy-url]" title="[wpv-taxonomy-title]"><img src="[taximage type="venture-type" slug="[wpv-taxonomy-slug]"]" alt="[wpv-taxonomy-title]" title="[wpv-taxonomy-title]" width="175" height="250" align="left" class="emotion-thumb"/><div id="emotion-name">[wpv-taxonomy-description]</div></a>[taximage type="venture-type" slug="[wpv-taxonomy-slug]"]</td>
         [wpv-item index=other]
          <td><a href="[wpv-taxonomy-url]" title="[wpv-taxonomy-title]"><img src="[taximage type="venture-type" slug="[wpv-taxonomy-slug]"]" alt="[wpv-taxonomy-title]" title="[wpv-taxonomy-title]" width="175" height="250" align="left" class="emotion-thumb"/><div id="emotion-name">[wpv-taxonomy-description]</div></a></td>
         [wpv-item index=5]
          <td><a href="[wpv-taxonomy-url]" title="[wpv-taxonomy-title]"><img src="[taximage type="venture-type" slug="[wpv-taxonomy-slug]"]" alt="[wpv-taxonomy-title]" title="[wpv-taxonomy-title]" width="175" height="250" align="left" class="emotion-thumb"/><div id="emotion-name">[wpv-taxonomy-description]</div></a></td></tr>
         [wpv-item index=pad]
            <td></td>
         [wpv-item index=pad-last]
            <td></td></tr>
      </wpv-loop>
   </table>
</div>
<!-- wpv-loop-end -->
[wpv-no-taxonomy-found][wpml-string context="wpv-views"]<strong>No taxonomy found</strong>[/wpml-string][/wpv-no-taxonomy-found]
[wpv-layout-end]

...as you can notice i placed the shortcode in two places because i see that in the functions.php we are asking to return the <img src /> tag instead of only the url...i might be wrong but this is what i understand but anyway just to check i added the shortcode in two places but the result is the same: hidden link

And here it how renders: hidden link

I could give you full access to ftp and wp-admin if this would help you to be sure that i'm not doing anything wrong.

Cheers,
Stelios

#105411

Dear Stelios,

You want just the url, so first change your code to:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
        $associations = get_option( 'taxonomy_image_plugin' );
        $term = get_term_by('slug', $atts['slug'], $atts['type']);
        if ( !empty($term) && isset( $associations[ $term->term_taxonomy_id ] ) ) {
                $attachment_id = (int) $associations[ $term->term_taxonomy_id ];
                return taxonomy_image_plugin_get_image_src( $attachment_id );
        }
}

Can you also make sure that you have WP_DEBUG enabled in case this code is producing error messages and we are missing them. I tried the code local before posting it.

Regards,
Caridad

#105482

SD

Dear Caridad,

WP_DEBUG was already enabled..the happy news are that with this code you gave above it now works 🙂
The issue though now IS that the images appear distorted, here you can see the difference the thumbs,
on the top are generated using WP-TYPES custom field and the thumbs at the bottom are using the code above (taxonomy images + shortcode) the html in views is exactly the same except the the shortcode for the image url and they are also using the same images: hidden link

Please advice,
Stelios

#105831

Dear Stelios,

I used an admin funciton that returns the images at 75x75. Try with this code instead:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
  $terms = apply_filters( 'taxonomy-images-get-terms', $atts['type'], array('slug' => $atts['slug']) );
  $term = reset( $terms );
  if ( !empty($term) && !empty($term['image_id']) ) {
    return wp_get_attachment_image_src( $term['image_id'], array(172,250) );
  }
}

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

#105944

SD

Hmm...now i get this error

Notice: The category taxonomy does not have image support. Manage Settings in /var/www/vhosts/mydomain.eu/httpdocs/newsite/wp-content/plugins/taxonomy-images/taxonomy-images.php on line 1117

Notice: The category taxonomy does not have image support. Manage Settings in /var/www/vhosts/mydomain.eu/httpdocs/newsite/wp-content/plugins/taxonomy-images/taxonomy-images.php on line 1117

Notice: The category taxonomy does not have image support. Manage Settings in /var/www/vhosts/mydomain.eu/httpdocs/newsite/wp-content/plugins/taxonomy-images/taxonomy-images.php on line 1117

Notice: The category taxonomy does not have image support. Manage Settings in /var/www/vhosts/mydomain.eu/httpdocs/newsite/wp-content/plugins/taxonomy-images/taxonomy-images.php on line 1117

Notice: The category taxonomy does not have image support. Manage Settings in /var/www/vhosts/mydomain.eu/httpdocs/newsite/wp-content/plugins/taxonomy-images/taxonomy-images.php on line 1117

I just changed the code in functions.php do i need to change anything on the shortcode at my view html as well ?

Please advice,
Stelios

#106615

Dear Stelios,

Have you enabled images for your taxonomy in Settings -> Taxonomy Images?

You dont need to change anything else.

Regards,
Caridad

#106728

SD

Hi Caridad,

Yes...it is the taxonomy that worked with the previous code but it was coming with stretched images hidden link
hidden link

Please advice,
Stelios

#107705

SD

Hi there,

Still trying to figure this out.

Plugin is activated, taxonomy has images enabled, images uploaded, it works(but with wrong dimensions-stretched images) with this code:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
        $associations = get_option( 'taxonomy_image_plugin' );
        $term = get_term_by('slug', $atts['slug'], $atts['type']);
        if ( !empty($term) && isset( $associations[ $term->term_taxonomy_id ] ) ) {
                $attachment_id = (int) $associations[ $term->term_taxonomy_id ];
                return taxonomy_image_plugin_get_image_src( $attachment_id );
        }
}

the next code you gave me does not work...still plugin and images active:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
  $terms = apply_filters( 'taxonomy-images-get-terms', $atts['type'], array('slug' => $atts['slug']) );
  $term = reset( $terms );
  if ( !empty($term) && !empty($term['image_id']) ) {
    return wp_get_attachment_image_src( $term['image_id'], array(175,250) );
  }
}

Is there any way to add dimensions to the first code ?

Please help,
Stelios

#108197

Dear Stelios,

Try with a combination of both:

add_shortcode('taximage', 'tax_image');
function tax_image($atts) {
        $associations = get_option( 'taxonomy_image_plugin' );
        $term = get_term_by('slug', $atts['slug'], $atts['type']);
        if ( !empty($term) && isset( $associations[ $term->term_taxonomy_id ] ) ) {
                $attachment_id = (int) $associations[ $term->term_taxonomy_id ];
                $image = wp_get_attachment_image_src( $attachment_id, array(175,250) );
return reset($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

#108368

SD

Hi Caridad,

This returns me this error:
Parse error: syntax error, unexpected T_VARIABLE in /var/www/vhosts/mydomain.eu/httpdocs/site/wp-content/themes/mytheme/functions.php on line 9

line 9 is this:

        $associations = get_option( 'taxonomy_image_plugin' );

Please advice,
Stelios

#108543

Dear Stelios,

Its strange, because there is no syntax error in that line. Maybe it is a hidden non-breaking space? Try removing the spaces on that line and retyping them to see if it resolves the problem.

Regards,
Caridad

#108732

SD

Hi caridad....you are right, that was a hidden space... thank you very much for everything now it works 🙂

If you just happened to know....can i make the images cropping to the size instead of squeezing(if are too big ) ? : hidden link ...the thumb on the top uploaded using WP-TYPES custom fields, the one at the bottom is the one we create using the code above....is there anyway to make the one at the bottom crop like the one at the top(in case the photo is too big) ?

Cheers,
Stelios

#109689

SD

No ?