The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Taxonomy Images
Get image of category parent? (4 posts)

  1. Blake Imeson
    Posted 3 years ago #

    I need this to be able to pull the Parent Category image as it will be annoying to have to set the same image for every child category.

    Is this possible?

    Right now I am using...

    <?php print $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '', array(
    			'image_size' => 'full'    ) );?>



  2. Blake Imeson
    Posted 3 years ago #

    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.

  3. Blake Imeson
    Posted 3 years ago #

    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?

  4. Daniele Raimondi
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Taxonomy Images
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic