D
D
Dima Malikov2015-11-09 21:13:51
PHP
Dima Malikov, 2015-11-09 21:13:51

How to display the names of subcategories of a certain category, Wordpress?

Good evening!
Made a portfolio with filtering based on this article.

<div class="container content">
    <div class="row row-margin">
      <?php $args = array(
        'parent'                   => 15,
        'hide_empty'               => 1,
        'number'                   => '0',
        'taxonomy'                 => 'category',
        'pad_counts'               => true );
         
        $catlist = get_categories($args);
      ?>
      <ul id="filters" class="clearfix">
        <li><span class="filter active" data-filter="portrait wedding">all</span></li>
        <?php
          foreach ($catlist as $categories_item) {
            echo "<li><span class=\"filter\" data-filter=\"$categories_item->cat_name\">" . $categories_item->cat_name . "</li>";
          }
        ?>
      </ul>
      <div id="portfoliolist">
        
        <?php 
          $query = new WP_Query( array( 
          'post_type' => 'post', 
          'posts_per_page' => -1,
          ) ); 
        ?>
        <?php 
          while ($query->have_posts()) : 
          $query->the_post();
        ?>
          <?php $category = get_the_category(); ?>
          <div class="col-lg-3 col-md-4 col-sm-6 col-xm-12 portfolio <?php echo $category[0]->cat_name; ?>" data-cat="<?php echo $category[0]->cat_name; ?>">
            <div class="block-active">
              <?php the_post_thumbnail('thumbnail'); ?>
            </div><!--/block-active-->
          </div><!--/col-->
        <?php endwhile; ?>
      </div><!--portfoliolist-->		
    </div><!--/row-->
  </div><!--/container-->

But to make it even more logical, I thought to filter based on subcategories. That is, there will be one category "Portfolio", from which all posts will be displayed, and filtering will already be by subcategories. But so far I have not succeeded. Someone can help?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Perin, 2015-11-09
@seoperin

It is more logical to make a custom post type "Portfolio", for it the taxonomy "Portfolio Categories" and display / filter by these categories.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question