tips and tricks for movable type
categories with most entries
April 04, 2004
This is a total copycat of the Scriptygoddess Most Commented On Entries, but I thought someone might find a use for it anyway. ;-)
Here, we'll use PHP to produce a list of the categories with the most entries.
Create a new Index Template with an output file of categories.inc with the following code in it:
<MTCategories>$catentries[<MTCategoryName>] =
<MTCategoryCount>;
</MTCategories>
<MTCategories>$catinfo[<MTCategoryName>] =
"<MTCategoryLabel>|<MTCategoryArchiveLink>|<MTEntries lastn="1"><MTEntryDate format="%m.%d"></MTEntries>";
</MTCategories>
?>
Make sure the box is checked to Rebuild this template automatically. Save the template and then rebuild it.
Where you want the listing to display, use this code:
# This is the path to the categories.inc:
include("/full/path/to/categories.inc");
echo "<ul>";
# This is the number of results you want to show:
$results = 10;
array_multisort($catentries, SORT_DESC, $catinfo);
$i = 0;
do {
$cats = explode("|", $catinfo[$i]);
$cat_name = $cats[0];
$cat_link = $cats[1];
$cat_updated = $cats[2];
echo "<li><b>$catentries[$i] entries</b>: <a href=\"$cat_link\">$cat_name</a> (updated $cat_updated)</li>";
$i++;
} while ($i<$results);
echo "</ul>";
?>
Be sure to change /full/path/to/categories.inc to point to the location of the new Index Template you created, and 10 to the number of categories you want in the listing.
TrackBack: 1
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/167)
» http://www.mamawrite.com/sideblog/002241.html
Excerpt: Display MT categories with most entries...
Weblog: Sideblog
Tracked: 04.04.04 08:22 AM