Created
September 20, 2011 16:49
-
-
Save rakeshr/1229634 to your computer and use it in GitHub Desktop.
wordpress - list main terms and sub terms under it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//list terms in a given taxonomy | |
$taxonomy = 'apptypes'; | |
$appargs=array( | |
'hide_empty' => false, | |
'orderby' => 'name', | |
'order' => 'ASC', | |
'parent' => '0' | |
); | |
$appterms = get_terms($taxonomy,$appargs); | |
?> | |
<ul> | |
<?php | |
foreach ($appterms as $appterm) { | |
echo '<li>' . '<a href="' . esc_attr(get_term_link($appterm, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $appterm->name ) . '" ' . '>' . $appterm->name.'</a></li>'; | |
$termID = $appterm->term_id; | |
$taxonomyName = $taxonomy; | |
$termchildren = get_term_children( $termID, $taxonomyName ); | |
foreach ($termchildren as $child) { | |
$termsub = get_term_by( 'id', $child, $taxonomyName ); | |
echo '<ul>'; | |
echo '<li>'.$termsub->name.'</li>'; | |
echo '</ul>'; | |
} } | |
?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment