• Resolved mywp2018

    (@mywp2018)


    I am trying to show respective child taxonomy term names and images on their parent term pages.

    For example:

    Parent Term A
    Child Term 1a
    Child Term 2a
    Child Term 3a

    On the Parent Term A taxonomy page, I want to show the taxonomy name and image for the 3 child terms 1a, 2a, and 3a and have each linked to their respective taxonomy term page. Child term 1a (name and image), for example, would link to the Child term 1a taxonomy page.

    Right now I can show the child name and link to the parent page. but wants to show the child name with the image. it would be great if you could help me with that. following is my code to display child on parent page:

    
    $term_id = get_queried_object_id();
    $taxonomy_name = 'post_tag';
    $term_children = get_term_children( $term_id, $taxonomy_name );
    
    foreach ( $term_children as $child ) {
               $term = get_term_by( 'id', $child, $taxonomy_name );
               $string .= '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
       }
       return $string;
    

    This code displays the name of the child associated to parent. But I also like to add image of child along with the name. It would be great if you could help me out with this. Thanks.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter mywp2018

    (@mywp2018)

    Hi, I got the solution after going through other topics in this forum. Following is the working code. hope it will help others who might face the same problem.

    
    $taxonomy_name = 'post_tag';
            $term_id = get_queried_object_id();
            $tax_images = get_option( 'taxonomy_image_plugin' );        
            $termchildren = get_terms( $taxonomy_name, array( 'parent' => $term_id, 'hide_empty' => true ) );
               foreach ( $termchildren as $child ) {
                   $tax_imageid = $tax_images[$child->term_id];
                   $child_image = wp_get_attachment_image ($tax_imageid, 'thumbnail');
                   $string .= '<span class="tagbox"><a class="taglink" href="' . esc_url( get_term_link( $child, $child->taxonomy ) ) . '"><span class="tagname">'.$child_image.'<p>'.$child->name.'</p></span></a><span class="tagcount">'. $child->count .'</span></span>';    
               }
               return $string;
    
Viewing 1 replies (of 1 total)
  • The topic ‘Show Taxonomy Child Terms (name and image) on Parent Term Page’ is closed to new replies.