I’m trying to create a list of links for a custom taxonomy along with the children of the terms. i.e:
<ul>
<li><a href="/telephony">Telephony</a>
<ul>
<li><a href="/blackberry">BlackBerry</a></li>
<li><a href="/fixed-ip">Fixed IP</a></li>
</ul>
</li>
<li><a href="/email">Email</a>
<ul>
<li><a href="/fax">Fax</a></li>
<li><a href="/text">Text</a></li>
<li><a href="/nhs-email">NHS Email</a></li>
</ul>
</li>
</ul>
So far I’ve got:
<?php
$termID = 451;
$taxonomyName = "service_line_category";
$termchildren = get_term_children( $termID, $taxonomyName );
echo '<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?>
However this only grabs the children of ‘$termID = 451;’ but I’m not sure how to modify this to get the parents and the children for all of the terms within ‘service_line_category’ in a list.
Any ideas?
Here is the piece of code you need :
Use a variable, you can do something like this:
@Alexcp so something like this:
Obviously this doesn’t work but is this along the right lines?