• Resolved Carin

    (@sparksfreebies)


    Hi! I love the shortcode for displaying all Ads with Post Counts, is there a way to Display a category with subcategories and post count only, not All or Top?
    I would like to choose 1 category and display with all subcategories in a list with post counts next, i did find a function if this is not possible with shortcode, what do you think?

    function wp_get_cat_postcount($id) {
        $cat = get_category($id);
        $count = (int) $cat->count;
        $taxonomy = 'category';
        $args = array(
          'child_of' => $id,
        );
        $tax_terms = get_terms($taxonomy,$args);
        foreach ($tax_terms as $tax_term) {
            $count +=$tax_term->count;
        }
        return $count;
    }
    
    	
    The total number of posts under "My Awesome Category" is <?php echo wp_get_cat_postcount(2); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    I am not sure how you would like to display this?

    Thread Starter Carin

    (@sparksfreebies)

    I have a Category Help Wanted Ads, with 8 subcategories, i would like to display a list (like the All) with 1 Cat, and its sub cats with post counts, see screenshot please. The shortcode or widget will be placed on its own page, that I will have other info on as well.
    2019-01-03_0902

    Plugin Author Greg Winiarski

    (@gwin)

    In WPAdverts there isn’t such functionality.

    To list all categories in a selected category you would need some custom programming, the code snippet here https://gist.github.com/ajithrn/9730807 should get you started it lists two methods which allow displaying subcategories from a selected taxonomy.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Subcategory List with Post Counts’ is closed to new replies.