Created
November 23, 2009 15:53
-
-
Save gesf/241138 to your computer and use it in GitHub Desktop.
ExpressionEngine: Listing categories' total posts...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
***************************************************** | |
ExpressionEngine: Listing categories' total posts... | |
***************************************************** | |
*/ | |
$category_group = 1; | |
$sql =<<<EndQuery | |
SELECT | |
ee_categories.cat_name, | |
ee_categories.cat_url_title, | |
COUNT(ee_category_posts.entry_id) AS count | |
FROM ee_categories | |
LEFT JOIN ee_category_posts | |
ON ee_categories.cat_id = ee_category_posts.cat_id | |
WHERE ee_categories.group_id = {$category_group} AND ee_categories.parent_id = 0 | |
GROUP BY ee_categories.cat_name; | |
EndQuery; | |
$query = $DB->query($sql); | |
foreach($query->result as $row) { | |
print '<li><a href="/category/' . $row['cat_url_title'] . '">' | |
. htmlentities($row['cat_name'], ENT_QUOTES) . ' [' . $row['count'] . ']</a></li>' . "\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment