scriptygoddess

26 Oct, 2002

collapsing archive list

Posted by: kristine In: MT hacks

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 :)

21 Responses to "collapsing archive list"

1 | kristine

October 29th, 2002 at 6:00 pm

Avatar

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.

2 | Elisa

December 11th, 2002 at 9:18 pm

Avatar

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. :)

3 | Cis

December 13th, 2002 at 8:19 am

Avatar

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!

4 | jenni

January 20th, 2003 at 12:52 am

Avatar

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!

5 | Lena

February 15th, 2003 at 1:30 am

Avatar

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!!!

6 | kristine

February 15th, 2003 at 12:55 pm

Avatar

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.

7 | Sherman Dorn

December 31st, 2003 at 1:17 am

Avatar

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.

8 | kadyellebee

October 26th, 2002 at 8:19 pm

Avatar

coding archive lists
What do normal people do on saturday afternoons? I don't know, I'm not normal 😉 I spend the afternoon figuring

9 | like the weather

October 29th, 2002 at 3:57 pm

Avatar

MT hacks at Scriptygoddess
scriptygoddess have come up with another winner – a way to collapse and expand your monthy archives list. Because I

10 | kadyellebee

October 29th, 2002 at 10:20 pm

Avatar

coding girl!
I've been a busy little coding girl today. Which didn't necessarily get my to do list caught up on, but

11 | Movable Type -- Kristine's Plugin Directory

November 30th, 2002 at 6:18 pm

Avatar

Glue Plugin
Used at the bottom of my kadyellebee index page for the last 15 entries, and on my category archives pages

12 | Live in the Delirious Cool

December 6th, 2002 at 5:06 pm

Avatar

Crossing off the days…
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.

13 | inluminent/weblog

December 23rd, 2002 at 12:49 am

Avatar

MT Plugin Directory
Tonight, I was working on some backend development for MarketingFix.com, our internet marketing weblog, and I found this list of

14 | My Little Life

January 5th, 2003 at 12:28 am

Avatar

Another Maintenance Update
It's getting late here and I've been playing around a lot with the code and such of the new layout.

15 | My Little Life

January 6th, 2003 at 11:18 am

Avatar

Many Special Thanks to My Other Half
The Other Half is the reason this site is up and running. He's the reason there are no annoying, ugly

16 | Daisyhead

January 26th, 2003 at 3:04 pm

Avatar

Sunday to do list
It's been a while since I've posted a "To Do" list, but since they really do seem to help keep

17 | The After Hours Pub

April 9th, 2003 at 2:53 pm

Avatar

Spend a morning in my shoes
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…

18 | Live in the Delirious Cool

August 20th, 2003 at 2:35 pm

Avatar

Things left behind.
Oh, and no more WeatherPixie.

19 | 8 Ways to Sunday

September 2nd, 2003 at 10:20 pm

Avatar

collapsible monthly archive lists in MovableType
If you've ever wanted to know how to do those nifty collapsible monthly archive lists, here's the lowdown from Scriptygoddess.

20 | Sherman Dorn

January 29th, 2004 at 9:38 pm

Avatar

Fixed code!
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…

21 | Sherman Dorn

January 29th, 2004 at 9:38 pm

Avatar

Fixed code!
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…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements