WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] help with custom hierachical list of taxonomies (2 posts)

  1. robertodimarco
    Member
    Posted 1 year ago #

    Hello! I've this code for generating a hierachical list of taxonomies :

    <?php
        	$taxonomy = 'finiture'; // change this to your taxonomy
        	$terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
        	if( $terms ) {
        	  echo '<ul>';
    
        	  $terms = trim( implode( ',', (array) $terms ), ' ,' );
        	  wp_list_categories( 'title_li=&taxonomy=' . $taxonomy . '&include=' . $terms );
    
        	  echo '</ul>';
        	}
        	?>

    But i need to insert after each <li> elements this code :
    <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>"/>

    To have this structure :

    <ul>Name<ul>
    <li><a><img />Sub-name</a></li>
    <li><a><img />Sub-name</a></li>
    <li><a><img />Sub-name</a></li>
    </ul>

    I think that i need to change wp_list_categories() with another function.... i'm trying with no results.... Someone can help me? Thank u!

  2. robertodimarco
    Member
    Posted 1 year ago #

    Solved! I've found this script:

    <?php
        	$args = array(
        	        'orderby'   => 'name',
        	        'order'     => 'ASC',
        	        'hide_empty'    => '0',
        	        'taxonomy' =>'finiture',
        	  );
    
        	$categories = get_categories($args);
    
        	foreach( $categories as $category ) { 
    
        	    $cat_ID = $category->term_id;
        	    $cat_name = $category->name;
        	    $cat_count = $category->count;
    
        	    echo '<p><strong>'.$cat_name.'</strong>';
    // here's my img
    echo '<img  src="'.z_taxonomy_image_url($category->term_id).'"/>';
        	    echo '</p>';  
    
        	}
        	?>

Topic Closed

This topic has been closed to new replies.

About this Topic