Skip to content

Instantly share code, notes, and snippets.

@gesf
Created November 23, 2009 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gesf/241138 to your computer and use it in GitHub Desktop.
Save gesf/241138 to your computer and use it in GitHub Desktop.
ExpressionEngine: Listing categories' total posts...
<?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