Not a developer? Go to MovableType.com

Plugin and Theme Directory

Categories by Date v1.0.1

By Dan Wolfgang
Posted February 11, 2010, in MT Tags, Templates, Widgets.

Details

Overview

Categories are not a date-related object in MT, so publishing categories in a date-structured way isn’t possible.

The CategoriesByDate plugin adds a block tag that will sort categories by date, with the most recently updated first. To determine the order of the categories, each category is compared to newest entry it is used in and that entry’s date sorts the category.

Use

This plugin adds the <mt:CategoriesByDate>...</mt:CategoriesByDate> block tag, which creates a category context. The following is a simple example of its use, and will return an unordered list of categories sorted by the date of their last use.

<mt:CategoriesByDate>
    <mt:If name="__first__">
    <ul>
    </mt:If>
        <li><mt:CategoryLabel></li>
    <mt:If name="__last__">
    </ul>
    </mt:If>
</mt:CategoriesByDate>

CategoriesByDate can also take a few arguments to help you refine the tag’s results:

  • The top argument can be set to a value of 1. This will return only the top-level categories.
  • The include_children argument can be set to a value of 1. This will cause the current category’s subcategories and their contents to be considered when determining the current category’s date.
  • The limit argument can be set to a positive number to limit the number of results returned, making it easy to create a list of the five recently-active categories, for example.

Below is an example that makes use of all of these arguments. Only the top-level categories are returned, but all subcategories are considered when determining the order of the top-level categories. Only the first 5 categories are returned. A link to the newest entry in that category is also published.

<mt:CategoriesByDate top="1" include_children="1" limit="5">
    <mt:If name="__first__">
    <ul>
    </mt:If>
        <li>
            <span class="category"><a href="<mt:CategoryArchiveLink>"><mt:CategoryLabel></a></span>:
            <mt:CategoryLabel setvar="current_category">
            <span class="entry"><mt:Entries category="$current_category" lastn="1"><a href="<mt:EntryPermalink>"><mt:EntryTitle></a></mt:Entries></span>
        </li>
    <mt:If name="__last__">
    </ul>
    </mt:If>
</mt:CategoriesByDate>

Acknowledgements

This plugin was commissioned by The Roster, a web marketing and design team, to Dan Wolfgang of uiNNOVATIONS.

Compatibility

Movable Type versions: 4.35.0

License

Perl Artistic


Back

Dan Wolfgang

Dan is an engineering creative and uses his vast knowledge of the web to solve unique client problems with specialized solutions. Complex or straightforward, his focus is to find the most efficient, functional, elegant, and stable solutions for each project. 10 years in web engineering and 14 more in the print publishing industry give him a special insight to the needs, restrictions, and workflows of content publishers, both traditional and new media. Dan is an active Movable Type community member who has written and contributed to countless plugins including some of the most popular: More Custom Fields, Poll Position, and Asset Image Quality.

Website: http://uinnovations.com
Twitter: @danwolfgang