• Blindacme

    (@blindacme)


    I am using the Taxonomy Meta plugin and have followed all instrauctions but feel like something is wrong with what I am doing. I just want to pull the image that is assigned to each category is a custom taxonomy and display it on a page template..

    php looks something like this:

    <?php
    $meta = get_option('additional');
    
        $images = $meta['community-image'];
    
    	echo '<ul>';
    
    	$args=array(
    		'orderby' => 'name',
    		'order' => 'ASC',
    		'taxonomy' => 'properties_community'
    	);
    
    	$categories=get_categories($args);
        // show image
        foreach($categories as $category) {
    		$src = wp_get_attachment_image_src($category, 'thumbnail');
        $src = $src[0];
    			echo '<li><a href="' . home_url() . '/?property_communities='. $category->slug .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '><img src="'.$src.'"/>' . $category->name.'</a> </li> ';
    		}
    	echo '</ul>'; ?>

    the github repo of the plugin can be found here: https://github.com/rilwis/taxonomy-meta

    please help, I get everything to show but the image and when I look in the source the image path isnt there just an empty img tag.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Blindacme

    (@blindacme)

    I can get an image to print using this:

    $meta = get_option('additional');
        if (empty($meta)) $meta = array();
        if (!is_array($meta)) $meta = (array) $meta;
        $meta = isset($meta['5']) ? $meta['5'] : array();
        $images = $meta['community-image'];
    
    		echo '<ul>';
        foreach ($images as $categories) {
        // get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
        $src = wp_get_attachment_image_src($categories, 'thumbnail');
        $src = $src[0];
    	$args=array(
    		'orderby' => 'name',
    		'order' => 'ASC',
    		'taxonomy' => 'properties_community'
    	);
    
    	$categories=get_categories($args);
        // show image
        foreach($categories as $category) {
    			echo '<li><a href="' . home_url() . '/?property_communities='. $category->slug .'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '><img src="'.$src.'"/>' . $category->name.'</a> </li> ';
    		}
    	}
    	echo '</ul>';

    but I cannot figure out how to make it where the image matches the category being displayed.. I just put the number 5 in there to see if it worked which it does but if I try using $category->term_id it doesnt work and I am a bit lost from here..

    Thread Starter Blindacme

    (@blindacme)

    Anyone able to tell me how to do this correctly? I know the problem with the second bit of code is this line:
    $meta = isset($meta['5']) ? $meta['5'] : array();
    which pulls the image for the category with the id of “5” but that displays that category image for all categories, so I need a way to pick it up for each category image. Wouldnt I just put that line in the foreach statement and then it would look something like:
    $meta = isset($meta[$category->term_id]) ? $meta[$category->term_id] : array();

    Wouldnt that be the approach? That doesnt work like that though but maybe spawn an idea for someone on how to get it to work for each category to pull the attached image..

    any help would be greatly appreciated

    Thread Starter Blindacme

    (@blindacme)

    No one? I would really appreciate the help

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Taxonomy Meta] trouble retrieving image’ is closed to new replies.