Blog category listing

I need to build a blog category listing for a sidebar. The result will look like this:

News [4]
Events [7]
Work [2]
etc ...

The list of categories and the total number of pages that have been allocated that category. Categories are select attributes. Each page has only one category. Does anyone have an idea how i can generate this type of listing?

View Replies:
magpie replied on at Permalink Reply
This is how I did this, grabing the select options then running a pagelist getting the total of pages with that category selected:

//get categories
        $ak = CollectionAttributeKey::getByHandle('blog_category');
        if (is_object($ak)) {
            $akc = $ak->getController();
            $options = $akc->getOptions();
            $cats = array();
            foreach($options as $opt) {
                if (!array_key_exists($opt->getSelectAttributeOptionDisplayOrder(), $cats)) {
                    $cats[$opt->getSelectAttributeOptionDisplayOrder()]['name'] = $opt->getSelectAttributeOptionValue();
                    $pl = new PageList();
                    $cats[$opt->getSelectAttributeOptionDisplayOrder()]['count'] = $pl->getTotal();

I then loop through the $cats array printing out $cat['name'] and $cat['count'].