Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following taxonomy structure:

  • Rich Media
    • course prep
    • demo modules
  • Moodle Setup
    • reteaching an old course
    • teaching new course

I want to display the parent tax name, and the child tax description (not the name). Child tax descriptions would link to tax archives.

This is what I have hacked together so far, but I'd like to avoid having to use multiple blocks of this kind - each with a different $term_id. Is there a more elegant way to do this so that any future changes would not require manually adding another block? Any help is much appreciated.

            <div class="tax-child">
                <h3><?php $term = get_term_by('slug', 'rich-media', 'preparingtoteach'); echo $term->name; ?></h3>
                <?php
                    $term_id = 249;
                    $taxonomy_name = 'preparingtoteach';
                    $termchildren = get_term_children( $term_id, $taxonomy_name );

                    echo '<ul>';
                    foreach ( $termchildren as $child ) {
                        $term = get_term_by( 'id', $child, $taxonomy_name );
                        echo '<li><a href="' . get_term_link( $term->name, $taxonomy_name ) . '">' . $term->description . '</a></li>';
                        }
                        echo '</ul>';
                ?>              
            </div>
share|improve this question
    
Which "another block" would that be? You are retrieving child terms by code so adding them would work automagically. –  Rarst May 1 '13 at 16:39
    
I meant that I would need another block of this code for, say, id 250, which is another parent taxonomy of 4 child taxonomies. I guess I'm looking for a way, in one block, to call all 4 parent taxonomies, and then to list their child taxonomies under their respective parents, rather than have 4 blocks (by individual ID) that list only its respective child tax's. –  user1505586 May 1 '13 at 20:22
    
Convert it into function that takes parent taxonomy as input, run 4 times with different input? This seems more PHP alley since you have WP bits working. –  Rarst May 1 '13 at 21:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.