Kategorieliste mit Anzahl der Kategorie-Kommentare [ 0 ]

Ähnlich wie die wp_list_categories listet der folgende Codeschnipsel alle Kategorien auf. Der Unterschied besteht allerdings darin, dass dahinter in Klammer nicht die Anzahl der Beiträge in den Kategorien angezeigt wird, sondern die Anzahl der Kommentare in der Kategorie.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<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>

Vielleicht hilfreich für den einen oder anderen. :-)


Found something helpful? Development of this and other free stuff on my site can be supported by a PayPal donation. Thank you!



Schreib einen Kommentar



Poets of the Fall - Carnival of Rust Video
Poets of the Fall - The Ultimate Fling Video
Poets of the Fall - Locking Up The Sun Video