Is your Monthly Archive list getting kinda long in your sidebar? Would you like to be able to show and hide it easily, with a few of the months still showing? Someone on the MTForums asked about this today, and I figured it out and thought I'd share it here.
The javascript for expanding/collapsing is a modification on Aaron's original tutorial and Jenn's version of it over here. I changed the variable names, so it shouldn't conflict with either of those options if you already have them installed.
Requirements: I used the MTGlue plugin (for use in MT 2.21 or higher) to make this easier. If you don't have access to that, I can write up the extra steps you'd need to take, but it definately makes it cleaner to code with it!
Also, the page that you put this on should be named with a .php extension. It requires that to parse the code, and won't work to show several of the months as a teaser otherwise.
Put this code in the head of your document:
<script language="javascript">
function showMoreArchives(archnum, archlink){
hid = ('hide' + (archnum));
unhid = ('click' + (archnum));
if( document.getElementById ) {
if( document.getElementById(hid).style.display ) {
if( archlink != 0 ) {
document.getElementById(hid).style.display = "block";
document.getElementById(unhid).style.display = "none";
} else { document.getElementById(hid).style.display = "none";
document.getElementById(unhid).style.display = "block"; }
} else { location.href = archlink;
return true; }
} else { location.href = archlink;
return true; }
}
</script>
If you already have a Script container, you can just insert the information inside of that.
And then place this where you'd like the archive list to appear:
<?
//put the number of months you want to appear before the "MORE" link here
$months = 3;
$month = array(<MTGlueContainer><MTArchiveList archive_type="Monthly">'<$MTArchiveTitle$>'<MTGlue>, </MTGlue></MTArchiveList></MTGlueContainer>);
$link = array(<MTGlueContainer><MTArchiveList archive_type="Monthly">'<$MTArchiveLink$>'<MTGlue>, </MTGlue></MTArchiveList></MTGlueContainer>);
$count=count($month);
for ($num=0; $num<$months; $num++) {
echo "<a name=\"", $num, "\"></a>";
echo "<a href=\"", $link[$num], "\">", $month[$num], "</a>";
echo "<br>";
}
echo "<span id=\"click", $num, "\">";
echo "<a href=\"", $link[$num], "\" onclick=\"showMoreArchives(", $num, ",'";
echo $link[$num], "#", $num, "');return false;\">";
echo "<b>click for more</b>";
echo "</a><br /></span>";
echo "<div id=\"hide", $num, "\" style=\"display: none\">";
for ($num=$months; $num<$count; $num++) {
echo "<a name=\"", $num, "\"></a>";
echo "<a href=\"", $link[$num], "\">", $month[$num], "</a>";
echo "<br>";
}
echo "<a href=\"#", $months, "\" onclick=\"showMoreArchives(";
echo $months, ",0);return true;\">";
echo "<b>close list</b></a></div>";
?>
If you have questions or comments, post them and I'll try to help you out!
Fixed so that the script doesn't conflict with the other functions