User discussions [ wordpress.org ]
- leochan369 on "Pagination with get_categories"
- depatterson on "Find and display parent categories"
- depatterson on "Find and display parent categories"
- ErikStromme on "get_categories count shows 0 when not empty"
- kparker2 on "Custom taxonomy category menu building. Please help"
- dhechler on "Get Parent Categories as Checkbox Inputs"
- Akay Akagunduz on "get_categories() with taxonomy not working in function.php"
- duck__boy on "get_categories() with taxonomy not working in function.php"
- Akay Akagunduz on "get_categories() with taxonomy not working in function.php"
- Digital Raindrops on "get_categories() with taxonomy not working in function.php"
2 User Note(s)
This example basically works like wp_list_categories with the only difference that it doesn't show the number posts in this category in parentheses, but the number of comments in the category:
<ul>
<?php
$ausgabe = '';
$allcats = get_categories( array('hide_empty'=>true) );
if( $allcats ) {
foreach( $allcats as $category ) {
$catnum = '';
$catposts = get_posts('numberposts=-1&category=' . $category->term_id);
foreach( $catposts as $catpost ) {
$catnum = $catnum + get_comments_number( $catpost->ID );
}
$cat_name = attribute_escape( $category->name );
$cat_name = apply_filters( 'list_cats', $cat_name, $allcats );
$link = '<a href="' . get_category_link( $category->term_id ) . '" ';
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
$link .= '>';
$link .= $cat_name . '</a>';
$ausgabe .= '<li class="cat-item cat-item-' . $category->term_id . '">' . $link . ' (' . $catnum . ')</li>' . "\n";
$catposts = array();
}
$ausgabe = apply_filters('wp_list_categories', $ausgabe);
} else {
$ausgabe .= '<li>' . __("No categories") . '</li>';
}
echo $ausgabe;
?>
</ul>
$categories = get_categories('include=<IDofCategory>');foreach ($categories as $cat) {
echo $cat->category_count." posts";
}