SHARE
TWEET

Count Post in Category

pustakakoran Apr 20th, 2017 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function.php:
  2. /*
  3. ---------------------
  4. Count Post in Category
  5. ---------------------
  6. */
  7. function wt_get_category_count($input = '') {
  8.     global $wpdb;
  9.     if($input == '')
  10.     {
  11.         $category = get_the_category();
  12.         return $category[0]->category_count;
  13.     }
  14.     elseif(is_numeric($input))
  15.     {
  16.         $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";
  17.         return $wpdb->get_var($SQL);
  18.     }
  19.     else
  20.     {
  21.         $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'";
  22.         return $wpdb->get_var($SQL);
  23.     }
  24. }
  25.  
  26.  
  27.  
  28. Tampilkan di category.php
  29. <?php echo wt_get_category_count(); ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top