views:

430

answers:

1

Hello there,

I'm working with MT for the first time and have encountered a little problem with displaying a list of monthly archives. I'd like to display a table where every year containing entries is a row, and all months are shown as cells in each row. Months containing entries are shown with their names wrapped in a link to the corresponding monthly archive.

The HTML I'm looking for would be something like:

<table>
<tr>
<th>2009</th>
<td><a href="link_to_jan_2009_archive">J</a></td>
<td>F</td>
<td>M</td>
<td><a href="link_to_apr_2009_archive">A</a></td>
<td>M</td>
<td>J</td>
<td>J</td>
<td><a href="link_to_aug_2009_archive">A</a></td>
<td>S</td>
<td>O</td>
<td>N</td>
<td>D</td>
</tr>
<tr>
<th>2008</th>
    ...
</tr>
</table>

At the moment I'm getting:

<table>
<tr>
<th>2009</th>
<td><a href="link_to_jan_2009_archive">J</a></td>
<td><a href="link_to_apr_2009_archive">A</a></td>
<td><a href="link_to_aug_2009_archive">A</a></td>
</tr>
<tr>
<th>2008</th>
    ...
</tr>
</table>

Here's the MT code in question:

<mt:ArchiveList type="Yearly" sort_order="descend">
<mt:ArchiveListHeader><table></mt:ArchiveListHeader>
 <tr>
  <th><$mt:ArchiveDate format="%Y"$></th>
  <mt:ArchiveList type="Monthly" sort_order="ascend">
  <td><$mt:ArchiveDate format="%b"$></td>
  </mt:ArchiveList>
 </tr>
 <mt:ArchiveListFooter>
</table>
</mt:ArchiveListFooter>
</mt:ArchiveList>

The code I have so far only produces months containing entries for each year. Could anyone help me to add the other months?

Thanks in advance,

Ross

A: 

The archive you want is very similar to an archive that I wrote about on Adventures in Movable Type.

Here's a modified version for your use case. You'll have to do a little deleting to get the month names shortened to the single letter you want.

Place this code into an index template and publish it:

<mt:SetHashVar name="month_map">
    <$mt:Var name="1" value="Jan"$>
    <$mt:Var name="2" value="Feb"$>
    <$mt:Var name="3" value="Mar"$>
    <$mt:Var name="4" value="Apr"$>
    <$mt:Var name="5" value="May"$>
    <$mt:Var name="6" value="Jun"$>
    <$mt:Var name="7" value="Jul"$>
    <$mt:Var name="8" value="Aug"$>
    <$mt:Var name="9" value="Sep"$>
    <$mt:Var name="10" value="Oct"$>
    <$mt:Var name="11" value="Nov"$>
    <$mt:Var name="12" value="Dec"$>
</mt:SetHashVar>

<table>
<mt:ArchiveList type="Yearly" sort_order="ascend">
    <mt:ArchiveListHeader><tr><$mt:ArchiveDate format="%Y" setvar="startYear"$></mt:ArchiveListHeader>
    <$mt:ArchiveDate format="%Y" setvar="archiveYear"$>
    <$mt:SetVar name="is_posts_year_{$archiveYear}" value="1"$>
    <mt:ArchiveList type="Monthly">
        <$mt:ArchiveDate format="%m%Y" setvar="monthYear"$>
        <mt:SetVarBlock name="links_{$monthYear}"><a href="<$mt:ArchiveLink$>"><$mt:ArchiveDate format="%b"$></a></mt:SetVarBlock>
    </mt:ArchiveList>
    <mt:ArchiveListFooter></tr><$mt:ArchiveDate format="%Y" setvar="endYear"$></mt:ArchiveListFooter>
</mt:ArchiveList>
<mt:For var="year" from="$startYear" to="$endYear">
    <mt:If name="is_posts_year_{$year}">
    <tr>
        <th><$mt:Var name="year"$></th>
    <mt:For var="month" from="1" to="12">
            <mt:SetVarBlock name="monthYear"><$mt:Var name="month" sprintf="%02d"$><$mt:Var name="year"$></mt:SetVarBlock>
        <td>
            <$mt:Var name="links_{$monthYear}" setvar="month_link"$>
            <mt:If name="month_link">
                <$mt:Var name="month_link"$>
            <mt:Else>
                <$mt:Var name="month_map{$month}"$>
            </mt:If>
        </td>
    </mt:For>
    </tr>
    </mt:If>
</mt:For>
</table>
Beau Smith