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.

Here is the structure of taxonomies what I want to display:

enter image description here

Here is my HTML code loop:

<li>
    <a>TAXONMOY 1</a>
    <div class="dropdownContainer">
        <div class="nav-column">
            <h3>TAXONMY CHILD 1</h3>
            <ul>
                <li>TAXONMY CHILD CHILD 1</li>
                <li>TAXONMY CHILD CHILD 2</li>
                <li>TAXONMY CHILD CHILD 3</li>
                <li>TAXONMY CHILD CHILD 4</li>
            </ul>
        </div>
        <div class="nav-column">
            <h3>TAXONMY CHILD 2</h3>
            <ul>
                <li>TAXONMY CHILD CHILD 1</li>
                <li>TAXONMY CHILD CHILD 2</li>
                <li>TAXONMY CHILD CHILD 3</li>
                <li>TAXONMY CHILD CHILD 4</li>
            </ul>
        </div>  
        <div class="nav-column">
            <h3>TAXONMY CHILD 3</h3>
            <ul>
                <li>TAXONMY CHILD CHILD 1</li>
                <li>TAXONMY CHILD CHILD 2</li>
                <li>TAXONMY CHILD CHILD 3</li>
                <li>TAXONMY CHILD CHILD 4</li>
            </ul>
        </div>          
    </div>
</li>
<li>
    <a>TAXONMOY 2</a>
    <div class="dropdownContainer">
        <div class="nav-column">
            <h3>TAXONMY CHILD 1</h3>
            <ul>
                <li>TAXONMY CHILD CHILD 1</li>
                <li>TAXONMY CHILD CHILD 2</li>
                <li>TAXONMY CHILD CHILD 3</li>
                <li>TAXONMY CHILD CHILD 4</li>
            </ul>
        </div>
        <div class="nav-column">
            <h3>TAXONMY CHILD 2</h3>
            <ul>
                <li>TAXONMY CHILD CHILD 1</li>
                <li>TAXONMY CHILD CHILD 2</li>
                <li>TAXONMY CHILD CHILD 3</li>
                <li>TAXONMY CHILD CHILD 4</li>
            </ul>
        </div>  
        <div class="nav-column">
            <h3>TAXONMY CHILD 3</h3>
            <ul>
                <li>TAXONMY CHILD CHILD 1</li>
                <li>TAXONMY CHILD CHILD 2</li>
                <li>TAXONMY CHILD CHILD 3</li>
                <li>TAXONMY CHILD CHILD 4</li>
            </ul>
        </div>          
    </div>
</li>
  • Just update my code:

            <?php
            $terms = get_terms( 'product_cat', array(
                    'hide_empty' => false,
                    'parent'     => 0
                ));
            foreach ($terms as $term) {
        ?>
        <li>
            <a href="<?php get_term_link( $term, 'product_cat' );?>" style="padding: 5px 20px"><?php echo $term->name; ?></a>
            <?php
                $childs = get_terms('product_cat',array(
                        'hide_empty' => false,
                        'parent'     => $term->term_id
                    ));
                if(!empty($childs)){
            ?>
            <div class="dropdownContainer">
                <?php 
                    foreach ($childs as $child) {
                ?>
                <div class="nav-column">
                    <h3><?php echo $child->name ?></h3>
                    <?php
                        $c_childs = get_terms('product_cat',array(
                                'hide_empty' => false,
                                'child_of'   => $child->term_id
                            ));
                        if(!empty($c_childs)){
                    ?>                      
                    <ul>
                        <?php 
                            foreach ($c_childs as $c_child) {
                        ?>                      
                        <li>
                            <a href="<?php echo get_term_link( $c_child, 'product_cat' );?>" title="<?php echo $c_child->name ?>"><?php echo $c_child->name ?></a>
                        </li>
                        <?php 
                            }//end child of child loop
                        ?>                          
                    </ul>
                    <?php 
                        }
                    ?>                      
                </div>
                <?php 
                    }
                ?>
            </div>
            <?php 
                }
            ?>
        </li>
        <?php } ?>
    
  • I'm note sure if there is another ways reduce the foreach loop!?
share|improve this question
    
Do you asking to give complete script for that? Hey! buddy, Try to do something using LOOP Read this CODEX also. After you have any doubt in your code. Community will help you asap. –  Big Bro Yesh Apr 17 at 7:44
3  
You forgot two important parts: Here is the code I have so far, and Here is where exactly I got stuck. Please add those to your question to make answers possible. –  toscho Apr 17 at 8:07
    
@toscho sorry, i just update my code! –  NT Thái Apr 17 at 16:02

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.