function printCategoryTree($categories, $anchor) { //looping to create a parentArray $parentArray = array(); foreach ($categories as $category) { if (!in_array($category->parent, $parentArray)) { array_push($parentArray, $category->parent); } } //looping again to build the category tree echo '<ul style="text-transform:uppercase;">'; foreach ($categories as $category) { if ($category->parent == $anchor) { echo '<li ><a class="wow fadeInUp" style="color:#0072BC; font-size:14px;" href="' . get_category_link($category) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . '>- ' . $category->name . '</a></li>'; if (in_array($category->cat_ID, $parentArray)) { printCategoryTree($categories, $category->cat_ID); } } } echo "</ul>"; }
<div class="container-fluid" style="background-color:#f2f2f2;" > <div class="container"> <div class="row"> <div class="col-sm-8" style="padding-top:8%; min-height:450px;"> <h2 class="wow fadeInUp" style="color:#0072BC;">BAABTRA MENTORING SCHEMES<br> Train to join</h2> <p class="wow fadeInUp"> As a bridge between the software universe and the regional talent, BAABTRA offers customised schemes for various portfolios, giving importance to core skills,technology-based practice and company-oriented grooming.</p> <h4 class="wow fadeInUp" style="color:#0072BC; margin-bottom:5px;"> Our courses are under the following categories:<h4> <?php $args = array('post_type' => 'course', 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'number' => ''); $categories = get_categories($args); //print categories as a tree structure printCategoryTree($categories, 0); ?> </div> <div class="col-sm-4 wow fadeInUp" style="padding-top:8%;"><img src="<?php echo get_template_directory_uri(); ?> /images/img.jpg"></div> </div> </div> </div> <!----section----end---->