Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Category Count (See related posts)

{exp:query sql="SELECT count(exp_category_posts.entry_id) AS count,exp_category_posts.cat_id, exp_categories.cat_name
FROM exp_categories, exp_category_posts WHERE exp_category_posts.cat_id = exp_categories.cat_id GROUP BY exp_categories.cat_name"}

<a href="{path=weblog/view}C{cat_id}/">{cat_name}
a> ({count})

{/exp:query}


Displays a list of categories with an entry count for each category. Alternatively, you can also use this query together with the {exp:weblog:categories} tag, making the query a lot smaller:

{exp:weblog:categories weblog="weblog1"}
<a href="{path=weblog/index}">{category_name}a>
{exp:query sql="SELECT count(exp_category_posts.entry_id) AS count
 FROM exp_category_posts  WHERE exp_category_posts.cat_id =  {category_id} "}
({count} entries)
{/exp:query}
{/exp:weblog:categories}

You need to create an account or log in to post comments to this site.


Related Posts