Support » Plugin: Taxonomy Images » get single.php image src

  • Resolved Redocneves

    (@redocneves)



    How to get the category image src on single.php

    My code don’t works:

    <?php $terms = apply_filters( 'taxonomy-images-get-terms', '' );
    if ( ! empty( $terms ) ) {
        foreach ( (array) $terms as $term ) {
            $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '', array(
            'image_id'  => $term->image_id ) );
            print 'src:'.$image_url.'</li>';
        }
    } ?>

    https://wordpress.org/plugins/taxonomy-images/

Viewing 1 replies (of 1 total)
  • Now Code Works like:

    header.php:

    <?php if(is_single()): $mainheadbar_img = taxonomy_images_plugin_single_src() ?>
    <?php else: $mainheadbar_img = apply_filters( 'taxonomy-images-queried-term-image-url', '', array('image_size' => 'full') );endif; ?>

    functions.php

    function taxonomy_images_plugin_single_src( $default, $args = array() ) {
    	$filter = 'taxonomy-images-list-the-terms';
    	if ( current_filter() !== $filter ) {
    		taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
    	}
    
    	$args['having_images'] = true;
    
    	if ( ! taxonomy_image_plugin_check_taxonomy( 'category', $filter ) ) {
    		return '';
    	}
    
    	$terms = apply_filters( 'taxonomy-images-get-the-terms', '', $args );
    
    	if ( empty( $terms ) ) {
    		return '';
    	}
    
    	$output = '';
    	foreach( $terms as $term ) {
    		if ( ! isset( $term->image_id ) ) {
    			continue;
    		}
    		$image_attributes = wp_get_attachment_image_src( $term->image_id, $args['image_size'] );
        $image_src = $image_attributes[0];
        break;
    	}
    
    	if ( ! empty( $image_src ) ) {
    		return $image_src;
    	}
    	return '';
    }

Viewing 1 replies (of 1 total)
  • The topic ‘get single.php image src’ is closed to new replies.