WordPress.org

Forums

Displaying 1st level children terms of taxonomy (1 post)

  1. chymera00
    Member
    Posted 5 years ago #

    I'm currently using this code to display the children of a term in taxonomy.php

    Unfortunately, it displays also the 2nd (3rd, 4th, etc..) level children terms and I only want to display the 1st level children.

    Hope someone can help me

    <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>

    <?php

    $taxonomy_term = $term->term_id;
    $i = 1;
    $taxtitle = '<p><strong class="text-large">Destinations in ' . $term->name . '</p>';

    $args=array(
    'orderby' => 'name',
    'order' => 'ASC',
    'child_of' => $taxonomy_term,
    );

    $categories=get_terms(destinations, $args);
    foreach($categories as $category) {

    if ($i == 1) { echo $taxtitle; $i++; };
    echo '<div class="hentry"><h2 class="entry-title" style="margin:0 0 0 95px;"> name ) . '" ' . '>' . $category->name.' </h2> ';
    echo '<div class="entry-content"><p>'. $category->description . '</p></div></div>'; }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic