Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function list_terms_listings( $atts ) {
- $a = shortcode_atts( array(
- 'id' => 10
- ), $atts );
- $term_id = $a['id'];
- $taxonomy_name = 'listing_category';
- $termchildren = get_terms( array(
- 'taxonomy' => $taxonomy_name,
- 'hide_empty' => false,
- 'orderby' => 'name',
- 'parent' => $term_id
- ) );
- $mainCat = get_term_by('id', $term_id, $taxonomy_name);
- echo '<h2><a href="' . get_term_link( $term_id, $taxonomy_name ) . '">'.$mainCat->name.'</h2>';
- echo '<ul>';
- foreach ( $termchildren as $child ) {
- $term = get_term_by( 'id', $child, $taxonomy_name );
- echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
- $termchildrenlvl1 = get_terms( array(
- 'taxonomy' => $taxonomy_name,
- 'hide_empty' => false,
- 'orderby' => 'name',
- 'child_of' => $child->id
- ) );
- if ($termchildrenlvl1 == true) {
- echo '<ul>';
- foreach ($termchildrenlvl1 as $termchildlvl1) {
- $termlvel1 = get_term_by( 'id', $termchildlvl1, $taxonomy_name );
- echo '<li><a href="' . get_term_link( $termchildlvl1, $taxonomy_name ) . '">' . $termlvel1->name . '</a></li>';
- }
- echo '</ul>';
- }
- }
- echo '</ul>';
- }
- // Add a shortcode that executes our function
- add_shortcode( 'dr_terms', 'list_terms_listings' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement