• Hi everybody,

    I am using a code that displays the (unique) children category (from a taxonomy) in my loop:

    $terms = get_the_terms(get_the_ID(), 'taxonomy');
    $slug= array();
    foreach ($terms as $term) {
    	if ($term->parent) $slug[] = $term->name;
    }
    echo '' . implode(', ', $slug);

    It works perfectly, but I’d like to have the sub-category with its hyperlink. Any help would be very much appreciated. Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    try to change this line:

    if ($term->parent) $slug[] = $term->name;

    to:

    if ($term->parent) $slug[] = '<a href="' . get_term_link( $erm->term_id, 'taxonomy' ) . '">' . $term->name . '</a>';

    http://codex.wordpress.org/Function_Reference/get_term_link

    (untested)

    Thread Starter krizba

    (@krizba)

    Thank you very much alchymyth!

    I finally used this code that works (close to yours):

    if ($term->parent) $slug[] = '<a href="' . get_term_link($term, $taxonomy) . '">' . $term->name. '</a>';

    (tested!)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘echo children category with hyperlink’ is closed to new replies.