WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Images
Trying to list the terms in a taxonomy with their image (22 posts)

  1. Agnes
    Member
    Posted 2 years ago #

    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/

  2. Tarun
    Member
    Posted 2 years ago #

    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.

  3. Agnes
    Member
    Posted 2 years ago #

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

  4. NAIJADEALZ
    Member
    Posted 1 year ago #

    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

  5. Tarun
    Member
    Posted 1 year ago #

    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.

  6. NAIJADEALZ
    Member
    Posted 1 year ago #

    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(); ?>
  7. NAIJADEALZ
    Member
    Posted 1 year ago #

    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
       ========================================================================== */
    ?>
  8. Tarun
    Member
    Posted 1 year ago #

    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') );
  9. NAIJADEALZ
    Member
    Posted 1 year ago #

    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.

  10. Tarun
    Member
    Posted 1 year ago #

    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.

  11. NAIJADEALZ
    Member
    Posted 1 year ago #

    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
       ========================================================================== */
    ?>
  12. NAIJADEALZ
    Member
    Posted 1 year ago #

    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 -->
  13. Tarun
    Member
    Posted 1 year ago #

    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.

  14. NAIJADEALZ
    Member
    Posted 1 year ago #

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

    Here

  15. Tarun
    Member
    Posted 1 year ago #

    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.

  16. NAIJADEALZ
    Member
    Posted 1 year ago #

    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

  17. NAIJADEALZ
    Member
    Posted 1 year ago #

    Dearest Tarun!

    WOW! It works now!
    I cannot believe how this happened.

    In the process of troubleshooting, I intalled all my plugins, intending to reinstall "Taxonomy images" only and re-test, but I completely forgot to re-install it.

    So, all along, i have been testing the various codes, without the plugin.

    Your code works, and so does the plugin.

    Just a little fine-tuning needed now, please help.

    I am using two codes, for comparison.

    What I'd prefer is to have the pictures displayed in 3 columns, with the name of the store below the image (not beside). For any "Store" without an associated image, display only the "Store name".
    Sort list by store name.

    Your code is producing the second div. I just need help configuring the described and removing the dots beside (they look like bullet points).

    <div class="itembox">
     <h1>"Tarun's Code"</h1>
    
    <div class="itemboxinner">
    	<?php
    	foreach( (array) $terms as $term){
    
    	echo '<li>';
    			 echo '<div style="margin: 0 10px 10px 0; float: left">';
    			  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 -->

    I really appreciate your help.

  18. NAIJADEALZ
    Member
    Posted 1 year ago #

    Here is the link

  19. NAIJADEALZ
    Member
    Posted 1 year ago #

    Just to update you.

    I have made some changes to the code and the page looks like this now.

    I can live with it this way, if i can arrange the images to grid, if you know what I mean, instead of the random display. and get rid of the annoying bullet points (dots beside the images).

    My code now looks like this

    get_header( ); 
    
    /*$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => $thistax) );*/
    
    $terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy'=>'store', 'image_size' => 'thumb', 'term_args' => 'hide_empty=0') );
    
    ?>
    
    <div class="itembox">
     <h1>Merchants and Brands</h1>
    
    <div class="itemboxinner">
    
    	 <span style='font-size: 20px;color: #006400'> Featured Merchants and Brands</span>
    
    	<?php
    	foreach( (array) $terms as $term){
    
    	echo '<li>';
    			 echo '<div style="margin: 0 10px 10px 0; float: left">';
    			  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</a>';
    	  			  echo '</li>';
    
    		  }
    
    		  echo '</ul>';
    
    	?>
    
    	</div><!-- end itembox innner -->
    
    <div class="itemboxinner">
    <span style='font-size: 20px;color: #006400'> All Listed Merchants and Brands</span>
    
    <span style='font-size: 16px;color: #006400'>
    	<?php echo $PPTDesign->TaxonomyDisplay(3,$thistax,1);  ?>	 
    
    	</div><!-- end itembox innner -->
    
    </div><!-- end itembox -->
    
    <?php get_footer(); 
    
    }
  20. Tarun
    Member
    Posted 1 year ago #

    Hi,

    The following code should work just fine:

    Replace this code in the php file

    <div class="itembox">
    <h1>Merchants and Brands</h1>
    <div class="itemboxinner"> <span style='font-size: 20px;color: #006400'> Featured Merchants and Brands</span>
      <?php
        echo '<ul class="featured-brands">';
    	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 '</li>';
    	}
    	echo '</ul>';
    
    	?>
    </div>
    <!-- end itembox innner -->

    And add this to your css file and you are good to go...

    ul.featured-brands {
        margin: 30px 0 0;
    }
    ul.featured-brands li {
        float: left;
        display: inline;
        height: 150px;
        margin: 0 20px 10px 0;
        text-align: center;
        width: 30%;
    }
  21. NAIJADEALZ
    Member
    Posted 1 year ago #

    Dear Tarun,

    The above works perfectly.

    You've been very helpful, I really appreciate it.

    Everything looks just right.

    Regards

  22. Hassan
    Member
    Posted 1 year ago #

    Tarun, you're the man!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic