• garydavison

    (@garydavison)


    Hi,
    First thanks for the great plugin, I’m trying to display images for custom taxonomies for each post, but I’m struggling. I have the following code:

    <?php $tax = 'colours'; ?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    					<div class="panel">
    	                	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(212, 212)); ?></a>
    	              		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    	                    <div class="swatches">
    	                   	  <ul>         
    
    	                      	<?php $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy'=> $tax ));
    							   foreach( (array) $terms as $term ) {
    							   	   echo '<li>' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</li>' ;
    							   }
    					         ?>
    	                      </ul>
    
    	                    </div>
    	                </div>
    				<?php endwhile; wp_reset_query(); ?>

    It does display the images for the custom taxonomies, unfortunately it displays them in every post, not just the posts that have bee allocated the taxonomy. What do I need to change to ensure that the taxonomy images are displayed for the post that has been allocated to rather than for all of the posts.

    Thanks
    Gary

    https://www.ads-software.com/extend/plugins/taxonomy-images/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Fields

    (@mfields)

    Hi,

    It looks like you might want to use one of the the filters. There are two:

    taxonomy-images-get-the-terms

    and

    taxonomy-images-list-the-terms

    Maybe try something like this:

    print apply_filters( 'taxonomy-images-list-the-terms', '', array(
    	'after'        => '</div>',
    	'after_image'  => '</span>',
    	'before'       => '<div class="my-custom-class-name">',
    	'before_image' => '<span>',
    	'image_size'   => 'detail',
    	'post_id'      => 1234,
    	'taxonomy'     => 'post_tag',
    ) );
    Thread Starter garydavison

    (@garydavison)

    Hi thanks for the response, I have tried the following:

    <?php query_posts( 'post_type=bedrooms&orderby=name&order=ASC' ); ?>
    				<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    					<div class="panel">
    	                	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(array(212, 212)); ?></a>
    	              		<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    	                    <div class="swatches">
    	                   	  <ul>
    					       <?php
    					         print apply_filters( 'taxonomy-images-list-the-terms', '', array(
    								'after'        => '</li>',
    								'after_image'  => '</span>',
    								'before'       => '<li>',
    								'before_image' => '<span>',
    								'image_size'   => 'detail',
    								'post_id'      => 1234,
    								'taxonomy'     => 'colours',
    							) );
    							?>
    	                      </ul>
    	                    </div>
    	                </div>
    				<?php endwhile; wp_reset_query(); ?>

    And it doesn’t appear to work, is there something obvious that I’m missing?

    Thanks
    Gary

    @garydavison You will never learn if you just copy and past.

    Did you look at what the code @michael Fields did?
    https://www.ads-software.com/extend/plugins/taxonomy-images/ Tells you what everything does.

    Try customizing your array for your needs and it should work just fine. It worked for me.

    I pasted my customized code below. It show the 3 newest blog post and includes there category image.

    – tough love

    <h2>Latest News</h2>
    	<ul>
    		<?php
    		$recent_posts = new WP_Query(array(
    			'post_type' => $post_type_array,
    			'cat' => $categories,
    			'posts_per_page' => 3
    		));
    		?>
    		<?php while($recent_posts->have_posts()): $recent_posts->the_post(); ?>
    			<li>
    				<?php
    				print apply_filters( 'taxonomy-images-list-the-terms', '', array(
    					'taxonomy'     => 'category',
    				) ); ?>
    				<a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_template_directory_uri(); ?>/img/service-sm-.png" alt=""/></a>
    			<h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2>
    			<span class="block-meta"><?php the_time(get_option('date_format')); ?>, <?php comments_popup_link(); ?></span>
    		</li>
    		<?php endwhile; ?>
    	</ul>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Taxonomy Images] Help displaying taxonomy images within the loop’ is closed to new replies.