Help - Search - Members - Calendar
Full Version: Year Header for MTArchiveList
Movable Type Community Forum > Additional Resources > Tips and Tricks
Babs
I'd be curious about this as well.
LunarMagic
K... I have no idea if this will work or not, I haven't tested it yet... if someone else who knows PHP could look it over? I'm going to go test it now. =)

And one prob with this code is that it will put a line break at the very top of your archives if your first archive date is previous to 2002.

CODE
<?

# set initial variables to current year

$year1 = <$MTDate format="%y"$>;
$year2 = <$MTDate format="%y"$>;

# start looping through the dates

print('<MTArchiveList archive_type="Monthly">');

# set variable to archive date and compare with previous archive date

$year2 = <$MTArchiveDate format="%y"$>;

if ($year2 != $year1) {
 print('<br>');
 print($year2);
 print('<br>');
}

# print archive link

print('<a href="<$MTArchiveLink$>"><$MTArchiveDate format="%B"$></a>  ');

# set variable 1 to archive date

$year1 == $year2;

# stop looping

print('</MTArchiveList>');

?>
garinungkadol
Ooooh! This is great!  :)

What happens if you have more than two year's worth of entries?
garinungkadol
biggrin.gif I'm using for a monthly archive here, in the sidebar.

It works like a charm. Thanks!!
LunarMagic
Love the look of your site... and the calender looks great too. ^_^
kraynight
I'm trying to format my Monthly Archive list in a way that there is a Year value for the header, then the months within each category of years.

For example:

2002
Mar Feb Jan
2001
Dec Nov Oct Sep...etc.

Here's what I'm using currently, which gives me the individual months, but is it possible to move the years to the headings like above?

CODE
<MTArchiveList archive_type="Monthly">
<$MTArchiveDate format="%B %y"$><BR>
</MTArchiveList>


Thanks for your help.

bcj.
LunarMagic
I think I could write a code in PHP for that... but there's probably an easier way. What I had been doing for my old entries... and I mean, with Blogger and Greymatter... was closing all entries from the previous year (or starting a new journal) and putting each year's list of weekly links on a seperate page.... it's not dynamic. With MT I think I could probably do it in coding. If no one else comes around maybe I'll take a crack at it. =) (but I'm new at php coding lol)
LunarMagic
Okay, I tested it and tweaked it and got the bugs out... this is set up for my individual archives, but it can be easily changed to suit monthly or weekly. Let me know if you have any problems. =)

CODE
<?

# set initial variables to current year

$year1 = <$MTDate format="%Y"$> + 1;
$year2 = <$MTDate format="%Y"$> + 1;
$counter = 0;

# start looping through the dates

print('<MTArchiveList archive_type="Individual">');

# set variable to archive date and compare with previous archive date

$year2 = <$MTArchiveDate format="%Y"$>;

if ($year2 != $year1) {
 if ($counter != 0) {
    print('<br>');
 }
 print($year2);
 print('<br>');
}

# print archive link
print('   <a href="<$MTArchiveLink$>"><$MTArchiveDate format="%B %e"$></a>  ');


# set variable 1 to archive date

$year1 = $year2;
$counter = 1;

# stop looping

print('</MTArchiveList>');

?>
LunarMagic
Doesn't matter, the "year1" and "year2" refer to the year of the current entry and the year of the previous entry... basically what it does is it checks to see if it needs to start a new line or not. It'll work for as many years as you have. =)

Also, in that second one i fixed the problem of it starting on the second line down, it'll work properly now.

let me know if you have any problems changing it to work for monthly. ^_^
LunarMagic
You're very welcome! And thanks for letting me see it in action. *G*
RoyalTS
I've done something similiar with my monthly archive links. Basically a PHP scripit creates a kind of calendar from the links. You can see what it looks like and also get the code here
kraynight
Excellent. I've been out of town so haven't had a chance to try it yet, but will very soon. Thanks for throwing the code together. My know-how with PHP is still in the inception stage.

bcj.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.