• Resolved Pete

    (@perthmetro)


    I have this function that lists child categories on the parent category archive page. Can someone help me to get the category descriptions displayed inline with the titles… thanks heaps.

    <?php
    
        $term = get_queried_object();
    
        $children = get_terms( $term->taxonomy, array(
            'parent'    => $term->term_id,
            'hide_empty' => false
        ) );
    
        if ( $children ) { 
            foreach( $children as $subcat )
            {
                echo '<li style="list-style-type:none"><a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . $subcat->name . '</a> </li>';
            }
        }
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The last string of the echo line is '</a> </li>'. Change it to this:
    '</a> '. $subcat->description .'</li>'

    You can add a separator char to the closing '</a> ' anchor tag, for example'</a> - '

    • This reply was modified 4 years ago by bcworkz. Reason: typo
    Thread Starter Pete

    (@perthmetro)

    Thanks, it works well.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to display category description in this function’ is closed to new replies.