K
K
Katsuro2020-04-27 19:48:42
WordPress
Katsuro, 2020-04-27 19:48:42

How to display each category level in a taxonomy on a separate page?

<?php

          $parents = get_terms('cat_catalog', [
            'hide_empty' => false,
            'parent'   => 0, 
          ]);

          foreach ($parents as $parent) {
            $term_link = get_term_link($parent,$taxonomy = 'cat_catalog');
            ?>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <a href="<?php echo $term_link; ?>">
                <div class="catalog-box">
                  <?php if($imgcat1=get_field("imgcat1",get_category($parent))){?>
                    <img src="<?php echo $imgcat1;?>"/>
                  <?php }?>
                  <p><?php echo $parent->name; ?></p>
                </div>
              </a>
            </div>
            <?php
          }

        ?>

This is the code in archive.php outputs the parent categories
<?php
      $taxonomy = get_terms('cat_catalog', [
        'hide_empty' => false,
        'parent'   => 0, 
      ]);


      foreach ($taxonomy as $taxonomys) {

        $terms = get_terms('cat_catalog', [
          'hide_empty' => false,
          'orderby'     => 'parent',
          'hierarchical' => true,
          'child_of' => $taxonomys->term_id, 
        ]);

        foreach ($terms as $term) {

          echo "<a href='".get_category_link( $term->term_id )."'>".$term->name."</a>";

        }

      }
    ?>

This is the code in taxonomy.php outputting child categories, but I need each category level to be on a separate page

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question