Archive Index Redo

archiveindex.gif I’ve changed the main archive index template from raw, unformatted month and category lists to something cleaner and slightly 2.0-ier. The monthly links are now arranged into neat rows of months grouped by year (all Kottke-style), and the category list is now a weighted “tag cloud” of links (although strictly speaking, I’m not using MT’s “tags” function). Larger words represent a higher number of entries under that category. This was all done with Movable Type templating tags and a bit of PHP — no plugins involved.

Here’s how I did the code for the year-and-month archives, basically building an associative array of URLs and default-format archive titles, exploding each title into a year and month, then looping through and printing the whole array by month, printing a line break and a bold year each time the years roll over:

<?php

$month_array = array();

<MTIfArchiveTypeEnabled type=”Monthly”>

  <MTArchiveList archive_type=”Monthly”>

    $month_array[‘<$MTArchiveTitle$>’] = ‘<$MTArchiveLink$>’;

  </MTArchiveList>

</MTIfArchiveTypeEnabled>

$month_array = array_reverse($month_array);

?>

<div class=”monthlies”>

<MTIfArchiveTypeEnabled type=”Monthly”>

<p>

  <?php

    $counter = 0;

    foreach ($month_array as $title => $link) {

      list($month, $year) = explode(” “, $title);

      if (!$counter) printf(“<b>%s:</b>n”, $year);

      printf(“t<a href=’%s’>%s</a>n”, $link, substr($month, 0, 3));

      if ($month != “December”) {

        $counter++;

      } else {

        $counter = 0;

        print “<br />”;

      }

    }

  ?>

</p>

</MTIfArchiveTypeEnabled>

</div><!– end .monthlies –>

And here’s my code for the weighted category cloud, building an array of categories, each category a nested associative array of info: category label, URL, entry count, and description. (I haven’t entered any category descriptions yet, so that variable doesn’t really come into play, but best to be thorough.) The entry count is then divided by whatever divisor gives you a decent font size when added to the base font size:

<?php

$category_array = array();

<MTIfArchiveTypeEnabled type=”Category”>

<MTTopLevelCategories>

  $category_array[] = array(

    ‘link’ => ‘<$MTCategoryArchiveLink$>’,

    ‘description’ => ‘<$MTCategoryDescription encode_php=”q”$>’,

    ‘label’ => ‘<MTCategoryLabel>’,

    ‘count’ => <MTCategoryCount>,

    );

</MTTopLevelCategories>

</MTIfArchiveTypeEnabled>

?>

<div class=”categories”>

<MTIfArchiveTypeEnabled type=”Category”>

  <p>

  <? foreach ($category_array as $cat) {

    extract($cat);

    $fontsize = floor(11 + ($count/15));

    printf(“<a href=’%s’ style=’font-size: %spx’ title=’%s’>%s</a>n”,

      $link, $fontsize, $description, $label);

  } ?>

  </p>

</MTIfArchiveTypeEnabled>

</div><!– end .categories –>

So that’s how I did it. MT and PHP gurus out there, let me know if I’ve gotten anything wrong; I’m pretty sure I’ve done something wrong, unnecessary, or needlessly complicated, and I’m open to simpler code solutions.