Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




Top Google Search Results

2 User Note(s)

Gravatar
Here's an example how to display how many posts are in a category.

$categories = get_categories('include=<IDofCategory>');
foreach ($categories as $cat) {
echo $cat->category_count." posts";
}
Gravatar
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>

Add New ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics