• Resolved John Leschinski

    (@picard102)


    I’m trying to display the number of posts in the current category archive. I have this so far, but I want it to ignore sticky posts when it does the count, or if that’s not feasable minus one from the count every time.

    function wt_get_category_count($input = '') {
    	global $wpdb;
    	if($input == '')
    	{
    		$category = get_the_category();
    		return $category[0]->category_count;
    	}
    	elseif(is_numeric($input))
    	{
    		$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.term_id=$input";
    		return $wpdb->get_var($SQL);
    	}
    	else
    	{
    		$SQL = "SELECT $wpdb->term_taxonomy.count FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_id=$wpdb->term_taxonomy.term_id AND $wpdb->terms.slug='$input'";
    		return $wpdb->get_var($SQL);
    	}
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Or this:

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      $args = array(
    	'category__in' => array($cat),
    	'post_type' => 'post',
    	'showposts' => -1,
    	'post__not_in' => get_option('sticky_posts'),
    	'caller_get_posts' => 1
      );
      $cat_posts = get_posts($args);
      echo 'cat has this many non-sticky posts '. count($cat_posts);
    }
    ?>
    Thread Starter John Leschinski

    (@picard102)

    Much simpler, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Count for category and excludes sticky posts’ is closed to new replies.