Advertisement
bastetmilo

Untitled

May 9th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2. function list_terms_listings( $atts ) {
  3.  
  4. $a = shortcode_atts( array(
  5. 'id' => 10
  6. ), $atts );
  7.  
  8. $term_id = $a['id'];
  9. $taxonomy_name = 'listing_category';
  10. $termchildren = get_terms( array(
  11. 'taxonomy' => $taxonomy_name,
  12. 'hide_empty' => false,
  13. 'orderby' => 'name',
  14. 'parent' => $term_id
  15. ) );
  16.  
  17. $mainCat = get_term_by('id', $term_id, $taxonomy_name);
  18.  
  19. echo '<h2><a href="' . get_term_link( $term_id, $taxonomy_name ) . '">'.$mainCat->name.'</h2>';
  20. echo '<ul>';
  21. foreach ( $termchildren as $child ) {
  22. $term = get_term_by( 'id', $child, $taxonomy_name );
  23. echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
  24. $termchildrenlvl1 = get_terms( array(
  25. 'taxonomy' => $taxonomy_name,
  26. 'hide_empty' => false,
  27. 'orderby' => 'name',
  28. 'child_of' => $child->id
  29. ) );
  30. if ($termchildrenlvl1 == true) {
  31. echo '<ul>';
  32. foreach ($termchildrenlvl1 as $termchildlvl1) {
  33. $termlvel1 = get_term_by( 'id', $termchildlvl1, $taxonomy_name );
  34. echo '<li><a href="' . get_term_link( $termchildlvl1, $taxonomy_name ) . '">' . $termlvel1->name . '</a></li>';
  35.  
  36. }
  37. echo '</ul>';
  38. }
  39. }
  40. echo '</ul>';
  41.  
  42. }
  43. // Add a shortcode that executes our function
  44. add_shortcode( 'dr_terms', 'list_terms_listings' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement