Advertisement
pusatdata

Count Post in Category

Apr 20th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  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(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement