List active taxonomy terms

I'm working on tweaking a template which has a filterable masonry layout. I made a taxonomy-categories.php and for the filtering I need the terms of the active taxonomy. The template which I'm using has this code inside it

ul id="filter"
                lia href="#" class="current" data-filter="*" title=""*/a/li
                ?php
                $categories = get_terms('categories');
                foreach( (array)$categories as $categorie){
                    $cat_name = $categorie-name;
                    $cat_slug = $categorie-slug;
                ?
                lia href="#" data-filter=".?php echo esc_attr($cat_slug); ?"?php echo esc_attr($cat_name); ?/a/li
                ?php } ?
            /ul

As you can see it takes all the terms from the whole taxonomy. I want it to take only the active's taxonomy sub-terms.

So if I am at URL example.com/portfolio/name_of_cat_one I want to list the children of that category.

I know that I can do that with get_term_by and tweaking a little to achieve my target, but after trying for many hours without success I ended up asking here :)

Topic advanced-taxonomy-queries loop custom-taxonomy Wordpress

Category Web


Well I did it..

        <ul id="filter">
                <li><a href="#" class="current" data-filter="*" title="">*</a></li>
                <?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
                <?php
                $term_id = $term->term_id;
                $taxonomy_name = 'categories';
                $termchildren = get_term_children( $term_id, $taxonomy_name );

                foreach ( $termchildren as $child ) {
                    $term = get_term_by( 'id', $child, $taxonomy_name );
                    echo '<li><a href="#" data-filter=".' . $term->slug . '">' . $term->name . '</a></li>';
                }
                ?>

            </ul>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.