WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Images
Return only the image url? (12 posts)

  1. tuttle425
    Member
    Posted 4 years ago #

    I am trying to return just the url of the taxonomy image rather than the img html code. Is there a way to accomplish this?

    Thanks

    http://wordpress.org/extend/plugins/taxonomy-images/

  2. mtomko
    Member
    Posted 3 years ago #

    I'm going to bump this up, because I am trying to figure this out as well.

    Any ideas would be most helpful.

    Thanks!

  3. Michael Fields
    Themer
    Plugin Author

    Posted 3 years ago #

    This is how you get the uri to the originally uploaded image on a taxonomy archive. Unfortunately, I cannot find a simple method to get a intermediate uri. Got this on the list for the next release though.

    global $taxonomy_images_plugin, $wp_query;
    if( isset( $taxonomy_images_plugin->settings ) ) {
    	$term_tax_id = 0;
    	$taxonomy = $wp_query->get_queried_object();
    	if( isset( $taxonomy->term_taxonomy_id ) ) {
    		$term_tax_id = $taxonomy->term_taxonomy_id;
    	}
    	if( array_key_exists( $term_tax_id, (array) $taxonomy_images_plugin->settings ) ) {
    		$image_id = $taxonomy_images_plugin->settings[$term_tax_id];
    		print wp_get_attachment_url( $image_id );
    	}
    }
  4. mtomko
    Member
    Posted 3 years ago #

    Thanks Michael.

    Forgive me for not exactly knowing how to use this. Do I need to change anything in there to specify which taxonomy I'm using?

    Basically I have a taxonomy called backgrounds and 2 "backgrounds" created in WP ("circles", "flowers", "wavy") each with their respective image associated with them.

    What I'm trying to do is use the taxonomy to easily change the background of a DIV by simply selecting a different "background" taxonomy. All I need is to print the URL of the image into an inline STYLE attribute for the background:url().

    Thoughts?

  5. Sparky
    Member
    Posted 3 years ago #

    bumpity bump. being able to get just the url would be ace.

    Thanks for a wonderful plugin!

  6. Michael Fields
    Themer
    Plugin Author

    Posted 3 years ago #

    Sparky,

    You're welcome! Please see the code above, it gets the url for the term being queried.

    Basically $taxonomy_images_plugin->settings is an array with term_taxonomy_id's as keys and image->ID's as values. If you have a term object, you can see if $term->term_taxonomy_id is a key in $taxonomy_images_plugin->settings and if so, pass the value to wp_get_attachment_url() to return a url.

  7. andyy
    Member
    Posted 3 years ago #

    How can I get the 'medium image url' to set the background image style for the div as per the example below?

    $cats = get_categories('taxonomy=my_taxonomy_category');
    foreach ( $cats as $c ) {
    $url = get_category_link( $c->term_id );
    echo '<div class="painting-category" id="' . $c->name . '" style="background-image:url(' . medium image url . ');">'."\n";
    echo '<h2>name . '" >'.$c->name.'</h2>';
        $img = $taxonomy_images_plugin->get_image_html( 'thumbnail', $c->term_taxonomy_id );
        if( !empty( $img ) )
            print '' . $img . '';/**/
    echo '</div>'."\n";
    }
  8. jfache
    Member
    Posted 3 years ago #

    Hi there,

    I just added this function to my functions.php to return the image attributes (url, width and height) of any size of any image associated with a term thanks to this plugin.

    function get_tax_thumb_url($term_tax_id, $size = 'category-thumb') {
    
      global $taxonomy_images_plugin;
      if( isset( $taxonomy_images_plugin->settings ) ) {
    	  if( array_key_exists( $term_tax_id, (array) $taxonomy_images_plugin->settings ) ) {
    		  $image_id = $taxonomy_images_plugin->settings[$term_tax_id];
    		  return wp_get_attachment_image_src( $image_id, $size );
    	  }
      }
    }

    It should maybe be included in the plugin's core.

  9. vkzawa
    Member
    Posted 3 years ago #

    @jfache

    Thanks, your function keeps my template code tidy.
    +1 vote to add this to plugin core.

  10. Michael Fields
    Themer
    Plugin Author

    Posted 3 years ago #

    FYI This plugin is going over a complete rewrite at the moment. Getting really close to a new release 0.7. A lot of time is being put into new functions to better access that data stored by the plugin so hopefully things like this will be easier in the future. Development can be followed on Github https://github.com/mfields/Taxonomy-Images

  11. vkzawa
    Member
    Posted 3 years ago #

    Awesome. Glad to hear it.

  12. Michael Fields
    Themer
    Plugin Author

    Posted 3 years ago #

    Sweet! Feel free to chime in here if you have specific requests: http://wordpress.mfields.org/2011/taxonomy-images-plugin-moving-forward/

    There are also some questions.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic