WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Taxonomy Images] Trying to list the terms in a taxonomy with their image

[Plugin: Taxonomy Images] Trying to list the terms in a taxonomy with their image

  • Agnes

    @agneslesagegmailcom

    Thanks for the plugin!
    I am using it to attach an image for a taxonomy called “collections”, that will display them museum objects (custom post type)

    SO I have a page called “collections” where, using a custom page template, I am trying to display all the collections available (ie all terms of the taxonomy “collections”
    NB: in fact, this template could also be used for other taxonomies that apply to the museum objects (departments, ethnic group, language, etc)

    I got this code display the list of terms (collections):

    <?php
    $terms = get_terms("collections");
     $count = count($terms);
     if ( $count > 0 ){
         echo "<ul>";
         foreach ( $terms as $term ) {
           echo "<li>" . $term->name . "</li>";
         }
         echo "</ul>";
     }
    ?>

    Now I have attached images to the collections, and am trying to display
    I tried this, but does not display anything:

    <?php
    $terms = apply_filters( ‘taxonomy-images-get-the-terms’, ”, array(‘taxonomy’ => ‘collections’) );
    foreach( (array) $terms as $term) {
    echo wp_get_attachment_image( $term->image_id, ” );
    echo $term->name;
    }
    ?>
    Any idea?
    Thanks a lot

    http://wordpress.org/extend/plugins/taxonomy-images/

Viewing 15 replies - 1 through 15 (of 21 total)
  • I have been trying to do the same thing. Changing ‘taxonomy-images-get-the-terms’ to ‘taxonomy-images-get-terms’ should make it work.

    <?php
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'collections') );
    foreach( (array) $terms as $term) {
      echo wp_get_attachment_image( $term->image_id, '' );
      echo $term->name;
    }
    ?>

    Hope this helps someone.

    Agnes

    @agneslesagegmailcom

    In the meantime I am not sure how I solved this… but thanks, and I am sure it will help someone too!

    Hi Agnes,

    Could you please share your template code for displaying the list of items in a taxnonomy and their associated images?

    My site is here Naijadeals.com and I’m trying to do a list of stores and their logo images.

    The taxonomy name is ‘stores’ and I’d like to list the names of the stores, as well as their images.

    Thank you

    Tarun

    @tarunmutreja

    Hi @niajadealz

    Here is a code that i used in one of my websites.

    <?php
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'stores') );
    
      if ( ! empty( $terms ) ) {
    
    	  echo '<ul class="links">';
    
    	  foreach( (array) $terms as $term ) {
    		  echo '<li>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'taxonomy-thumb' ) . '</a>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a>';
    		  echo '</li>';
    	  }
    
    	  echo '</ul>';
    
      }
    ?>

    Note: “taxonomy-thumb” is a registered custom image size. You can register your own by adding the following code in functions.php

    add_image_size( 'taxonomy-thumb', 96, 72, true );

    Refer: http://codex.wordpress.org/Function_Reference/add_image_size

    Hope this helps.

    Dear Tarun,

    Thank you for taking time out to reply.

    I have tried the code, however, it just returns a blank page, no store list or images.

    The template code is as follows. I am a complete newbie to php. so please help some more

    <?php
    /**
     * Template Name: Example ke
     *
     * This is an example template for you to customize.
     * It may not fit exactly in with your theme because all themes are different.
     * It's always best to work with your theme's page.php to get things right.
     */
    
    get_header();
    
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'stores') );
    
      if ( ! empty( $terms ) ) {
    
    	  echo '<ul class="links">';
    
    	  foreach( (array) $terms as $term ) {
    		  echo '<li>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</a>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a>';
    		  echo '</li>';
    	  }
    
    	  echo '</ul>';
    
      }
    
    get_footer(); ?>

    My code looks like this now, still not working

    <?php
    /*
    Template Name: [Example Ke]
    */
    
    /* =============================================================================
       THIS FILE SHOULD NOT BE EDITED // UPDATED: 16TH MARCH 2012
       ========================================================================== */ 
    
    global  $userdata; get_currentuserinfo(); // grabs the user info and puts into vars
    
    $wpdb->hide_errors(); nocache_headers();
    
    $thistax = get_post_meta($post->ID, 'type', true);
    
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'stores') );
    if($thistax == ""){
    
    	if(current_user_can('administrator')){
    
    		if(isset($_GET['type'])){
    
    			update_post_meta($post->ID, 'type', $_GET['type']);
    
    		}else{
    
    		wp_die( 'Select the list type:  <form action="" method="get"><select name="type"><option value="location">Country/State/City List</option><option value="store">Stores List</option></select><input name="" type="submit" value="Save Selection" /></form>' );
    
    		}
    
    	}else{
    
    	wp_die( 'This page has not yet been setup.' );
    
    	}
    
    }
    
    $GLOBALS['LOADTHISTAX'] = $thistax;
    $GLOBALS['COLUMNS'] = "3";
    
    /* =============================================================================
       LOAD IN PAGE CONTENT // V7 // 16TH MARCH
       ========================================================================== */
    
    $hookContent = premiumpress_pagecontent("taxonomy"); /* HOOK V7 */
    
    if(strlen($hookContent) > 20 ){ // HOOK DISPLAYS CONTENT
    
    	get_header();
    
    	echo $hookContent;
    
    	get_footer();
    
    }elseif(file_exists(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme')."/_tpl_taxonomy.php")){
    
    		include(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme').'/_tpl_taxonomy.php');
    
    }else{ 
    
    /* =============================================================================
       LOAD IN PAGE DEFAULT DISPLAY // UPDATED: 25TH MARCH 2012
       ========================================================================== */ 
    
    get_header( ); ?> 
    
    <div class="itembox">
    
        <h1><?php the_title(); ?></h1>
    
        <div class="itemboxinner"> 
    
    	<?php echo $PPTDesign->TaxonomyDisplay(3,$thistax,1);  ?>	 
    
      <?php if ( ! empty( $terms ) ) {
    
    	  echo '<ul class="links">';?>
    
    	  <?php foreach( (array) $terms as $term ) {
    		  echo '<li>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</a>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a>';
    		  echo '</li>';
    	  }
    
    	  echo '</ul>';
    
      }?>
    
    	</div><!-- end itembox innner -->
    
    </div><!-- end itembox --> 
    
    <?php get_footer(); 
    
    }
    /* =============================================================================
       -- END FILE
       ========================================================================== */
    ?>
    Tarun

    @tarunmutreja

    After looking at your website URL it seems that the the taxonomy slug is ‘store’ and not ‘stores’. Try changing the code to the following:

    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'store') );

    Dear Tarun,
    Thanks a lot.

    I have changed to ‘store’

    code is now this:

    <?php
    /*
    Template Name: [Example Ke]
    */
    
    /* =============================================================================
       THIS FILE SHOULD NOT BE EDITED // UPDATED: 16TH MARCH 2012
       ========================================================================== */ 
    
    global  $userdata; get_currentuserinfo(); // grabs the user info and puts into vars
    
    $wpdb->hide_errors(); nocache_headers();
    
    $thistax = get_post_meta($post->ID, 'type', true);
    
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'store') );
    
    if($thistax == ""){
    
    	if(current_user_can('administrator')){
    
    		if(isset($_GET['type'])){
    
    			update_post_meta($post->ID, 'type', $_GET['type']);
    
    		}else{
    
    		wp_die( 'Select the list type:  <form action="" method="get"><select name="type"><option value="location">Country/State/City List</option><option value="store">Stores List</option></select><input name="" type="submit" value="Save Selection" /></form>' );
    
    		}
    
    	}else{
    
    	wp_die( 'This page has not yet been setup.' );
    
    	}
    
    }
    
    $GLOBALS['LOADTHISTAX'] = $thistax;
    $GLOBALS['COLUMNS'] = "3";
    
    /* =============================================================================
       LOAD IN PAGE CONTENT // V7 // 16TH MARCH
       ========================================================================== */
    
    $hookContent = premiumpress_pagecontent("taxonomy"); /* HOOK V7 */
    
    if(strlen($hookContent) > 20 ){ // HOOK DISPLAYS CONTENT
    
    	get_header();
    
    	echo $hookContent;
    
    	get_footer();
    
    }elseif(file_exists(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme')."/_tpl_taxonomy.php")){
    
    		include(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme').'/_tpl_taxonomy.php');
    
    }else{ 
    
    /* =============================================================================
       LOAD IN PAGE DEFAULT DISPLAY // UPDATED: 25TH MARCH 2012
       ========================================================================== */ 
    
    get_header( ); ?> 
    
    <div class="itembox">
    
        <h1><?php the_title(); ?></h1>
    
        <div class="itemboxinner"> 
    
    	<?php echo $PPTDesign->TaxonomyDisplay(3,$thistax,1);  ?>	 
    
      <?php if ( ! empty( $terms ) ) {
    
    	  echo '<ul class="links">';?>
    
    	  <?php foreach( (array) $terms as $term ) {
    		  echo '<li>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</a>';
    		  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a>';
    		  echo '</li>';
    	  }
    
    	  echo '</ul>';
    
      }?>
    
    	</div><!-- end itembox innner -->
    
    </div><!-- end itembox --> 
    
    <?php get_footer(); 
    
    }
    /* =============================================================================
       -- END FILE
       ========================================================================== */
    ?>

    and output is just a list of stores listed alphabetically, no image.

    Tarun

    @tarunmutreja

    It seems that the else condition is never executed in which you have the taxonomy images code. The code that is executing is either within
    if(strlen($hookContent) > 20 ) condition or in elseif(file_exists(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme')."/_tpl_taxonomy.php"))

    Try adding some echo statements to test which condition is being executed and then go from there on.

    The else condition is getting executed Tarun, when i change the number of columns displayed from 3 to 2, i see the change.

    code is like this now but all i get is an empty image box.

    here

    <?php
    /*
    Template Name: [Naija Stores List Template]
    */
    
    global  $userdata; get_currentuserinfo(); // grabs the user info and puts into vars
    
    $wpdb->hide_errors(); nocache_headers();
    
    $thistax = get_post_meta($post->ID, 'type', true);
    
    $image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'store') );
    
    if($thistax == ""){
    
    	if(current_user_can('administrator')){
    
    		if(isset($_GET['type'])){
    
    			update_post_meta($post->ID, 'type', $_GET['type']);
    
    		}else{
    
    		wp_die( 'Select the list type:  <form action="" method="get"><select name="type"><option value="location">Country/State/City List</option><option value="store">Stores List</option></select><input name="" type="submit" value="Save Selection" /></form>' );
    
    		}
    
    	}else{
    
    	wp_die( 'This page has not yet been setup.' );
    
    	}
    }
    
    $GLOBALS['LOADTHISTAX'] = $thistax;
    $GLOBALS['COLUMNS'] = "3";
    
    $hookContent = premiumpress_pagecontent("taxonomy"); /* HOOK V7 */
    
    if(strlen($hookContent) > 20 ){ // HOOK DISPLAYS CONTENT
    
    	get_header();
    
    	echo $hookContent;
    
    	get_footer();
    
    }elseif(file_exists(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme')."/_tpl_taxonomy.php")){
    
    		include(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme').'/_tpl_taxonomy.php');
    
    }else{ 
    
    get_header( ); ?> 
    
    <div class="itembox">
    
        <h1><?php the_title(); ?></h1>
    
        <div class="itemboxinner"> 
    
    	<?php echo $PPTDesign->TaxonomyDisplay(3,$thistax,1);  	?>
    	<?php foreach( (array) $terms as $term){
    	echo wp_get_attachment_image( $term->image_id, '' );
    	echo $term->name;
    	echo "<div style='margin: 0 10px 10px 0; float: left'><img src='$term' /></div>";
     	print apply_filters( 'taxonomy-images-queried-term-image', '' );}?>
    
    	</div><!-- end itembox innner -->
    
    </div><!-- end itembox --> 
    
    <?php get_footer(); 
    
    }
    
    /* =============================================================================
       -- END FILE
       ========================================================================== */
    ?>

    Here is the code getting executed

    <div class="itemboxinner"> 
    
    	<?php echo $PPTDesign->TaxonomyDisplay(3,$thistax,1);  	?>
    	<?php foreach( (array) $terms as $term){
    	echo wp_get_attachment_image( $term->image_id, '' );
    	echo $term->name;
    	echo "<div style='margin: 0 10px 10px 0; float: left'><img src='$term' /></div>";
     	print apply_filters( 'taxonomy-images-queried-term-image', '' );}?>
    
    	</div><!-- end itembox innner -->
    Tarun

    @tarunmutreja

    Try changing the code to the following:

    <?php
    /*
    Template Name: [Naija Stores List Template]
    */
    
    global  $userdata; get_currentuserinfo(); // grabs the user info and puts into vars
    
    $wpdb->hide_errors(); nocache_headers();
    
    $thistax = get_post_meta($post->ID, 'type', true);
    
    if($thistax == ""){
    
    	if(current_user_can('administrator')){
    
    		if(isset($_GET['type'])){
    
    			update_post_meta($post->ID, 'type', $_GET['type']);
    
    		}else{
    
    		wp_die( 'Select the list type:  <form action="" method="get"><select name="type"><option value="location">Country/State/City List</option><option value="store">Stores List</option></select><input name="" type="submit" value="Save Selection" /></form>' );
    
    		}
    
    	}else{
    
    	wp_die( 'This page has not yet been setup.' );
    
    	}
    }
    
    $GLOBALS['LOADTHISTAX'] = $thistax;
    $GLOBALS['COLUMNS'] = "3";
    
    $hookContent = premiumpress_pagecontent("taxonomy"); /* HOOK V7 */
    
    if(strlen($hookContent) > 20 ){ // HOOK DISPLAYS CONTENT
    
    	echo 'i am inside if';
    
    	get_header();
    
    	echo $hookContent;
    
    	get_footer();
    
    }elseif(file_exists(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme')."/_tpl_taxonomy.php")){
    
    		echo 'i am inside elseif';
    
    		include(str_replace("functions/","",THEME_PATH)."/themes/".get_option('theme').'/_tpl_taxonomy.php');
    
    }else{ 
    
    echo 'i am inside else';
    
    get_header( ); 
    
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => $thistax) );
    
    ?>
    
    <div class="itembox">
    
        <h1><?php the_title(); ?></h1>
    
        <div class="itemboxinner"> 
    
    	<?php echo $PPTDesign->TaxonomyDisplay(3,$thistax,1);  	?>
    
    	<?php
    	 foreach( (array) $terms as $term ) {
    		 echo '<div style="margin: 0 10px 10px 0; float: left;">';
    		 echo wp_get_attachment_image( $term->image_id, '' );
    		 echo $term->name;
    		 echo '</div>';
    	  }
    	?>
    
    	</div><!-- end itembox innner -->
    
    </div><!-- end itembox --> 
    
    <?php get_footer(); 
    
    }
    
    /* =============================================================================
       -- END FILE
       ========================================================================== */
    ?>

    Let me know what you get.

    I got the usual alphabetical list without the logo, plus your echo ‘am inside else’

    Here

    Tarun

    @tarunmutreja

    Sorry, for the delay… had to work on an urgent project.

    This code should work perfectly fine, as it did for me.

    <?php
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'store') );
    foreach( (array) $terms as $term ) {
      echo '<div style="margin: 0 10px 10px 0; float: left;">';
      echo wp_get_attachment_image( $term->image_id, '' );
      echo $term->name;
      echo '</div>';
    }
    ?>

    Since it is not working and I can’t look at the inner functionality of this premium theme. I would suggest you to contact the theme support where you purchased this theme from.

    Hi Tarun, and thanks for your help.

    Unfortunately i could not get that code to work, and the theme support is not of much help. They advised that I hire someone instead of providing help like they advertised.

    I got two plugins and combined their functions unto a single page here.

    Until I am able to get something exactly like I want, that is it for now.

    Apologies for getting back to you late.

    Regards

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘[Plugin: Taxonomy Images] Trying to list the terms in a taxonomy with their image’ is closed to new replies.