• Resolved superpotion

    (@superpotion)


    Thought you might find this useful: a function to output a list of category (or term) images with links. I use it inside the PHP widget plugin to get a clickable list of category images.

    function z_list_taxonomy_images($taxonomy = "category") {
    
    	$args=array(
    	  'orderby'  => 'name',
    	  'order'    => 'ASC',
    	  'taxonomy' => $taxonomy
    	  );
    
    	$terms=get_categories($args) ;
    
    	if (count($terms)>0) {
    
    		$html = '<ul class="z_list_taxonomy_images">' . "\n" ;
    		foreach($terms as $term) {
    			$html .= '   <li>' . "\n";
    			$html .= '      <a href="' . get_term_link(intval($term->term_id), $term->taxonomy) . '" title="' . $term->name . '">';
    			$html .= '         <img src="' . z_taxonomy_image_url($term->term_id) . '" />';
    			$html .= '      </a>' . "\n";
    			$html .= '   </li>' . "\n";
    		}
    		$html .= '</ul>' . "\n";
    
    	} else {
    
    		$html = '<p>' . "Taxonomy " . $taxonomy . " not found.</p> \n" ;
    	}
    
    	echo $html ;
    }

    Simply include the code in your (child) theme’s functions.php or modify the plugin directly (I used the author’s function naming convention for this reason).

    Enjoy

    Denis

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

  • The topic ‘List images with links’ is closed to new replies.