WordPress.org

Forums

Categories Images
[resolved] List the Custom Taxonomy with with image (10 posts)

  1. markyeoj
    Member
    Posted 2 years ago #

    Hi, I registered a custom post type 'Recipe' and created a custom taxonomy 'Recipe Category'.. now I want to display the list of Categories under the Recipe Category including their respective images. How to do that?

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

  2. Muhammad
    Member
    Plugin Author

    Posted 2 years ago #

    have you checked the examples in the plugin documentation here ?
    I think what you need is the 4th one in using inside loop.

    check it and reply back if you still any help

    Thanks

  3. markyeoj
    Member
    Posted 2 years ago #

    I used this code.. but did not work,

    <div id="recipe-category" class="rolls">
    Recipe Category
    <ul>
     <?php foreach (get_terms('your_taxonomy') as $cat) : ?>
     <li>
     <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
     <a href="<?php echo get_term_link($cat->slug, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a>
     </li>
     <?php endforeach; ?>
    </ul>
    </div>

    here's the image

  4. Muhammad
    Member
    Plugin Author

    Posted 2 years ago #

    :)
    for sure it won't work cuz you have to change the word 'your_taxonomy' to your taxonomy name :)

  5. markyeoj
    Member
    Posted 2 years ago #

    ouch. haha.. sorry, I copied the wrong code..

    here's the code from my template..

    <div id="recipe-category" class="rolls">
    Recipe Category
    
    <ul>
     <?php foreach (get_terms('recipecategory') as $cat) : ?>
     <li>
    <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
    <a href="<?php echo get_term_link($cat->slug, 'your_taxonomy'); ?>"><?php echo $cat->name; ?></a>
    </li>
    <?php endforeach; ?>
    </ul>
    
    </div>
  6. Muhammad
    Member
    Plugin Author

    Posted 2 years ago #

    :) you still have to change the other 'your_taxonomy' word inside the loop

  7. markyeoj
    Member
    Posted 2 years ago #

    yes.. I already changed that.. looks like the problem is with the custom post type UI plugin.. even I use a simple

    <?php
    
    $taxonomy = 'recipecategory';
    $tax_terms = get_terms($taxonomy);
    ?>
    <ul>
    <?php
    foreach ($tax_terms as $tax_term) {
    echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
    }
    ?>
    </ul>

    still not working.

  8. Muhammad
    Member
    Plugin Author

    Posted 2 years ago #

    you mean even without using my plugin ? if so, please make sure of the taxonomy name is the same name you had registered it with.

  9. markyeoj
    Member
    Posted 2 years ago #

    Yes even without using your plugin. this is very frustrating, I hope the support of Custom Post Type UI can help me to fix this.

  10. Iamhere
    Member
    Posted 2 years ago #

    Try this updated code.
    You can remove the timthumb stuff if you don't use that.

    // taxonomy term archives
    $post_type = get_post_type(); // find out if CPT
    $taxonomies = get_object_taxonomies($post_type); // Find taxonomies
    if($taxonomies){
    foreach($taxonomies as $taxonomy){
       // only want hierarchial -- no tags please
        if(is_taxonomy_hierarchical($taxonomy)){
    
            $terms = get_terms($taxonomy); // find out "terms" e.g. catoegries, for each taxonomy
    
    		// if($terms){
                foreach ( $terms as $term ) {  ?>
    
    <li>
    
                <h1><a href="<?php echo get_term_link($term->slug, $taxonomy); ?> "><? echo $term->name; ?></a></h1>
    
                <div class="imgBox">
                <? if (function_exists('z_taxonomy_image_url')) { ?>
    			<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo z_taxonomy_image_url($term->term_id); ?>&h=196&w=285&zc=1" alt="<?php the_title(); ?>" />
                <?php } else { ?>
                    <img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=/images/placeholder.png&h=196&w=285&zc=1" alt="<?php the_title(); ?>" />
                 <?	 } ?>
                </div>
    
                </li>
    
                <?	
    
              }
        }
    }
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Categories Images
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic