wp list categories with total number of posts in parenthises ( ) some usefull examples


/ Published in: PHP
Save to your folder(s)

Show wp categories in drop down list like ...


Copy this code and paste it in your HTML
  1. join all categoeis and show total post in category
  2. ==================================================
  3. <?php
  4. $categories = get_categories();
  5. foreach ($categories as $cat) {
  6. if ($cat->category_parent != 0) {
  7. echo '<span style="padding-left:10px;">';
  8. }
  9. echo 'category_nicename.'/">'.$cat->cat_name.' ('.$cat->category_count.')';
  10. if ($cat->category_description != '') {
  11. echo ' - '.$cat->category_description;
  12. }
  13. if ($cat->category_parent != 0) {
  14. echo '</span>';
  15. }
  16. echo ' ';
  17. }
  18. ?>
  19.  
  20. remove parenthises from wp_list_categories()
  21. ==============================================
  22. $variable = wp_list_categories('echo=0&show_count=1&child_of=&title_li=');
  23. $variable = str_replace(array('(',')'), '', $variable);
  24. $variable = str_replace("<ul>" , '' , $variable );
  25. echo $variable;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.