Support » Plugin: Taxonomy Images » Get image of category parent?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Well, one step forward. I switched to this…

    <?php if (is_category()) { ?>
    			<?php print $image_url = apply_filters( 'taxonomy-images-list-the-terms', '', array(
    		    'after'        => '</div>',
    			'after_image'  => '',
    			'before'       => '<div class="header-category-image col-full">',
    			'before_image' => '',
    			'image_size' => 'full'    ) );?>
    		<?php } ?>

    Now the only issue is that the image won’t show up on Single Posts – any solutions out there for that? Seems everyone has the same hurdle with that.

    If I want the image I assigned to a category to appear on a single post (that lives in that category) do I need to find a different way to accomplish that than this plugin?

    Hi Blake, there is a quick & dirty way to get the image associated to a certain term (not the actually queried term) with this plugin: all associations are kept in an array, as a wp option, so you can get the entire array just using

    $associations = get_option( 'taxonomy_image_plugin' );

    Every array element has the term_id as key and the attachment id as value; so we can write a function to get the image associated to a specific term ID, like this one:

    if ( !function_exists( 'get_term_image' ) ){
    	function get_term_image($args=array()) {
    		$defaults = array (
    			'term_id' => 0,
    			'size' 	=> 'thumbnail',
    			'classes' => 'wp-attachment term-image'
    		// Parse incoming $args into an array and merge it with $defaults
    		$args = wp_parse_args( $args, $defaults );
    		// OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
    		extract( $args, EXTR_SKIP );
    		if ( $term_id > 0) {
    			$associations = get_option( 'taxonomy_image_plugin' );//check tax images created by plugin Taxonomy Images
    			if ( is_array( $associations ) && count ($associations) ){
    				if ( isset($associations[$term_id]) ) {
    					$term_img=wp_get_attachment_image( $attachment_id, $size, false, array( 'class'	=> $classes ) );
    		return $term_img;

    Then you can get the html tag of the image associated with a term id, like this:

    	"term_id" => $my_term_id,
    	"size" => "my_custom_size_or_one_of_small_medium_large",
    	"classes" => "class1 class2 class3"
    $image = get_term_image($args);

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get image of category parent?’ is closed to new replies.