Hey there together,
I ran into yet another problem that I can't seem to figure out even after searching the forum and consulting Google...
On my category archive page I want to display the number of posts from the category the user is just looking at. And I don't want to install yet another plugin to do that, there must be some simple one lince code that I could just add to the template file.
Any help would be highly appreciated!
Thanks a lot,
Martin
<?php
$cat = get_query_var('cat');
$categories=get_categories('include='.$cat);
if ($categories) {
foreach($categories as $category) {
echo 'Posts in this category = ' . $category->count;
}
}
?>
Thanks a lot Michael. That worked. Would you be able to let me know the same kind of code to use to display the total number of posts within a monthly archive?
display the total number of posts within a monthly archive
<?php
if ( is_month() ) {
$month = get_query_var('monthnum');
$year = get_query_var('year');
$countposts=get_posts("year=$year&monthnum=$month");
echo 'the count of posts in ' . $month .'/'.$year . ' is ' . count($countposts);
}
?>
67thavenue
Member
Posted 3 years ago #
What's the code to display the number of post for just one particular category? For example: Comic.
Thanks!
AlDavies
Member
Posted 3 years ago #
Hi 67thavenue,
Try this code where 123 is the ID of the category. This will single out just that category.
<?php
$cat = get_query_var('cat');
$categories=get_categories('include=123'.$cat);
if ($categories) {
foreach($categories as $category) {
echo '' . $category->count;
}
}
?>