Basic code for filtering posts by category and total count
-
I am new to understanding API’s and need very ‘simple’ code to create a loop that just looks for total count of all posts of category 4 as well as child cats: 5-10 (parent cat name = ‘programs’)
I have tried the following but am struggling with understanding how some of these template tags work as well as global variables et al…
Almost there with version 4, but it delivers a count of 82526 (total count s/b 23, do i have to reset the count to 0 after while loop?
see this page: http://howlingwolfmedia.com/site3/classlist/try snippet 4
<p class="hiliteBlu"><strong>Total Classes: <span class="hiliteBlue"> <?php $categories=get_categories('include=5,6,7,8,9,10'); if ($categories) { foreach($categories as $category) { echo $category->count ; } } ?> </span>classes</strong></p>try snippet 3
<?php $the_query = new WP_Query (); ?> <?php if is_category (4); ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php $count_posts = wp_count_posts(); ?> <?php endwhile; ?> <?php endif; ?>try snippet 2
<?php query_posts('cat=4'); ?> <?php if (have_posts() : the_post(); ?> <?php $count_posts = wp_count_posts(); ?> <?php //endif; ?>try snippet 1
<?php $categories=get_categories('include=4'); ?> <?php if ($categories) { foreach($categories as $category) ; echo $category->count'; ?>
The topic ‘Basic code for filtering posts by category and total count’ is closed to new replies.