Support » Plugin: Taxonomy Images » [Plugin: Taxonomy Images BETA] Return only the image url?

Viewing 11 replies - 1 through 11 (of 11 total)
  • mtomko

    (@mtomko)

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

    Any ideas would be most helpful.

    Thanks!

    Plugin Contributor Michael Fields

    (@mfields)

    Themer

    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 );
    	}
    }
    mtomko

    (@mtomko)

    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?

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

    Thanks for a wonderful plugin!

    Plugin Contributor Michael Fields

    (@mfields)

    Themer

    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.

    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";
    }

    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.

    @jfache

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

    Plugin Contributor Michael Fields

    (@mfields)

    Themer

    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

    Awesome. Glad to hear it.

    Plugin Contributor Michael Fields

    (@mfields)

    Themer

    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.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Taxonomy Images BETA] Return only the image url?’ is closed to new replies.