Advertisement
rakeshr

final list main terms and sub terms under it

Sep 18th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. //list terms in a given taxonomy
  3. $taxonomy = 'apptypes';
  4. $appargs=array(
  5.   'hide_empty' => false,
  6.   'orderby' => 'name',
  7.   'order' => 'ASC',
  8.   'parent' => '0'
  9. );
  10. $appterms = get_terms($taxonomy,$appargs);
  11. ?>
  12. <ul>
  13. <?php
  14. foreach ($appterms as $appterm) {
  15. echo '<li>' . '<a href="' . esc_attr(get_term_link($appterm, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $appterm->name ) . '" ' . '>' . $appterm->name.'</a></li>';
  16. $termID = $appterm->term_id;
  17. $taxonomyName = $taxonomy;
  18. $termchildren = get_term_children( $termID, $taxonomyName );
  19. foreach ($termchildren as $child) {
  20.     $termsub = get_term_by( 'id', $child, $taxonomyName );
  21.     echo '<ul>';
  22.     echo '<li>'.$termsub->name.'</li>';
  23.     echo '</ul>';
  24. } }
  25. ?>
  26. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement