Weighted Categories Plugin

Sunday, February 13, 2005

Update 06/03/05: I’ve updated the plugin so that it will work with ExpressionEngine 1.3
Update 09/09/05: Added a sort parameter, variables for the category image and description, and cleaned up the code a bit.
Update 07/23/07: Added documentation for parent_id parameter, fixed bug when there are no results to be displayed, and variable for category URL title.

I wrote a very basic plugin to display weighted categories. Most of the credit goes to these two however. And to the person who wrote the developer documentation because I would have been lost otherwise. :p

Check out my archives for an example.

You can download the plugin here and it’s also listed in the Plugin Library.

ABOUT

This plugin will display a linear list of the weighted categories. The categories are weighted on the number of entries assigned to the category.

PARAMETERS

group_id - the id of the category group you want to display. To figure out the id number of a category group, look in the exp_category_groups table. You can include several category groups by separating them with the pipe | character. If you have a category group assigned to multiple weblogs, the plugin will count entries from all of the weblogs.

weblog - the short name of the weblog you want to display (the plugin will limit the categories shown to those in the weblog). You can include several weblogs by separating them with the pipe | character.

min_font - size of the smallest category (category with the least number of entries). The default value is 12.

max_font - size of the largest category (category with the most number of entries). The default value is 30.

backspace - the number of characters that you want to chop off the end of the display.

order_by - how you want to sort the categories. Valid options for this parameter are ‘count’, ‘cat_id’, ‘category’, ‘category_description’, ‘category_image’, ‘group_id’, and ‘weblog’.

sort - the sort order. Valid options for this parameter are ‘desc’ or ‘asc’. The default is ascending.

parent_id - the category parent id, if you want to display only a subset of categories.

VARIABLES

SINGLE VARIABLES
{category} - the name of the category.
{category_description} - the category description.
{category_image} - the category image.
{cat_id} - the id of the category.
{cat_url_title} - the URL title for the category.
{count} - the number of entries in the category.
{font_size} - the weighted font size.
{group_id} - the id of the category group that the category belongs to.
{weblog} - the short name of the weblog.

Note: the {weblog} variable may not be accurate if you used the group_id parameter when calling the plugin. This is because when you use the group_id parameter, it counts the number of entries in each category of a category group from all weblogs, and not just one weblog. It will not be accurate if you specify several weblogs using the weblog parameter, and these weblog have the same category group. It is accurate only if each category group is assigned to one weblog.

CONDITIONAL VARIABLES
All of the single variables above can be used in a conditional statement.

{if no_results}{/if}
Used if there are no categories.

EXAMPLE

The following will display an alphabetical weighted list of categories from one weblog:
{exp:weightedcategories weblog=“weblog1” min_font=“10” max_font=“20” backspace=“3” order_by=“category”}
<span style=“font-size: {font_size}px;” title=”{count} entries”><a href=”{path=“weblog/index”}C{cat_id}”>{category}</a></span> - {/exp:weightedcategories}

The following will display an alphabetical weighted list of categories from two weblogs, with a different output depending on the weblog:
{exp:weightedcategories weblog=“weblog1|weblog2” min_font=“10” max_font=“20” backspace=“3” order_by=“category”}
{if weblog==“weblog1”}
<span style=“font-size: {font_size}px;” title=”{count} entries”><a href=”{path=“weblog/index”}C{cat_id}”>{category}</a></span> - {/if}
{if weblog==“weblog2”}
<span style=“font-size: {font_size}px;” title=”{count} entries”><a href=”{path=“weblog2/index”}C{cat_id}”>{category}</a></span> - {/if}
{/exp:weightedcategories}

The following will display a weighted list of categories belonging to two category groups, with the categories from the first category group listed first:
{exp:weightedcategories group_id=“1|2” min_font=“10” max_font=“20” order_by=“group_id”}
<span style=“font-size: {font_size}px;” title=”{count} entries”>{category} ({count})</span>
{/exp:weightedcategories}

Comments & Trackbacks

Post a comment.

The trackback URL for this entry is:

Gravatar for Lisa

1. Lisa United States said:

on May 04 2005 @ 01:00 AM

Hey Yvonne, you should submit this to the plugins site. I just went searching for it there (my first stop for plugins usually) and was surprised it wasn’t there. =)

Avatar for Yvonne

2. Yvonne Canada said:

on May 04 2005 @ 03:35 PM

Thanks for reminding me Lisa, I forgot to submit it. smile

Gravatar for Tony Walsh

3. Tony Walsh Canada said:

on Sep 08 2005 @ 06:27 PM

Hey, great plugin! I just can’t figure out how to change the sort order between ascending or descending. Any tips there? I used the ‘sort’ parameter but it doesn’t seem to work (or I’m using it wrong).
Thanks smile

Avatar for Yvonne

4. Yvonne Canada said:

on Sep 09 2005 @ 08:37 PM

Tony, I’ve updated the plugin to allow for a sort order. The new version isn’t up at the plugin library yet but you can download it here.

Gravatar for Tony Walsh

5. Tony Walsh Canada said:

on Sep 09 2005 @ 09:11 PM

Super, thanks much!

Gravatar for Adam Khan

6. Adam Khan Italy said:

on Feb 16 2006 @ 09:32 AM

Nice plugin — thanks.

Gravatar for karsten

7. karsten Germany said:

on Mar 05 2006 @ 10:06 AM

the links from my category cloud goes to the full articles. is it possible to show only the title onstead of the full article?

Avatar for Yvonne

8. Yvonne Canada said:

on Mar 05 2006 @ 05:34 PM

Karsten, if you want to show only the titles, then you’ll need to create another template that does that, and then link to that new template.

Gravatar for karsten

9. karsten Germany said:

on Mar 05 2006 @ 05:36 PM

ah ok, thxs :-)

Gravatar for Susan Kitchens

10. Susan Kitchens United States said:

on Jun 22 2006 @ 12:48 PM

Hi there! I use your plugin for categories on my site. Thanks. Nice work, that.

I’m trying to do a roll-your-own weighted display of some items. I generate them through a SQL query, and the results include a count of items. Is there some way I could adapt the plugin for a special-use case of weighted display of a list? (or should I be asking this on the EE boards?)

Post a Comment

Commenting is not available in this weblog entry.

Live Preview

Avatar

Comment Author

Mar 11 2010 @ 01:05 AM