collapsing archive list
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
January 29th, 2004 at 9:38 pm
Found out what was wrong with the collapsing archive list tip from Scriptygoddess: nothing! I had forgotten to add a code in one file to…
January 29th, 2004 at 9:38 pm
Found out what was wrong with the collapsing archive list tip from Scriptygoddess: nothing! I had forgotten to add a code in one file to…
September 2nd, 2003 at 10:20 pm
If you've ever wanted to know how to do those nifty collapsible monthly archive lists, here's the lowdown from Scriptygoddess.
August 20th, 2003 at 2:35 pm
Oh, and no more WeatherPixie.
April 9th, 2003 at 2:53 pm
I say, ok, smileys NOW! Gotta start from scratch, so I go over to the MT website to get into the support forums. But I never make it that far. The latest entry on MT is that they've been nominated…
January 6th, 2003 at 11:18 am
The Other Half is the reason this site is up and running. He's the reason there are no annoying, ugly
January 26th, 2003 at 3:04 pm
It's been a while since I've posted a "To Do" list, but since they really do seem to help keep
December 23rd, 2002 at 12:49 am
Tonight, I was working on some backend development for MarketingFix.com, our internet marketing weblog, and I found this list of
January 5th, 2003 at 12:28 am
It's getting late here and I've been playing around a lot with the code and such of the new layout.
December 6th, 2002 at 5:06 pm
My archives list is getting a little long-in-the tooth, and I'd like to find another way to package them. Just another step in my quest for a real whiz-bang blog.
November 30th, 2002 at 6:18 pm
Used at the bottom of my kadyellebee index page for the last 15 entries, and on my category archives pages
October 26th, 2002 at 8:19 pm
What do normal people do on saturday afternoons? I don't know, I'm not normal
October 29th, 2002 at 3:57 pm
scriptygoddess have come up with another winner – a way to collapse and expand your monthy archives list. Because I
October 29th, 2002 at 10:20 pm
I've been a busy little coding girl today. Which didn't necessarily get my to do list caught up on, but
January 20th, 2003 at 12:52 am
I am having a hard time implementing this. I've added my plugins directory and even tested it via Mena's instructions in the Plugins documentation for MT, but it's still not listing my individual entries. The URL is http://daisyhead.org/past/archives-test.php
Is anyone willing to help me out? Thanks!
February 15th, 2003 at 1:30 am
Lord, I would LOVE to be able to use this. Unfortunately, my host doesn't allow custom CGI on the server, so I can't use MT. Would anyone happen to know if there's something like this out there not written specifically for MT? I've looked everywhere after seeing this – nada darn thing.
VERY nice script!!!
February 15th, 2003 at 12:55 pm
Lena — you could use this script in another program, but you'd have to modify it so it had something else for the variables
I've actually used it on a page without any MT Tags in it, just for the contracting/expanding purposes, so it is possible to modify it a great deal. You could even hard code the dates in for your archive list if you were using it in a by-hand journal.
December 31st, 2003 at 1:17 am
Hmmn… the idea is wonderful, but the following appears in place of the three months!
"; echo "", $month[$num], ""; echo "
"; } echo ""; echo ""; echo "click for more"; echo "
"; echo "
"; for ($num=$months; $num<$count; $num++) { echo ""; echo "", $month[$num], ""; echo "
"; } echo ""; echo "close list
"; ?>
I'm not familiar with PHP, so I'm truly scratching my head.
October 29th, 2002 at 6:00 pm
If you'd like to add a date header into the list, so that it shows like this:
2002
October [linked]
September [linked]
and so on, I came up with some additional code over in the original thread on the MTForums.
December 11th, 2002 at 9:18 pm
This was an excellent script! Thanks very much. Incidentally, I am running an older version of MT and my Other-Half erased all the "MTGlue" stuff. We tested everything and it works just the same.
December 13th, 2002 at 8:19 am
I use several things that require my page to end in .shtml so I created a file archives.php with basic html that had the script in the header and the php code in the body and then used this to call the file into my index:
<!–#include virtual="archives.php"–>.
Works like a charm. Thanks so much, Kristine!