Heather asked me if it were possible to make your archives listing only show the last 6 months one way, and then the rest another way.
She wanted the last 6 months of archives to display like:
November 2002
02 Nov 19: post title
02 Nov 02: post title
October 2002
02 Oct 30: post title…
and then the rest of the archives just in month format like this:
April 2002
March 2002
At first I would have said to do something with <MTArchiveList archive_type-"monthly" offset="6"> but it that "offset" attribute doesn't seem to get applied like that (it only offsets specific ENTRIES, not archive types). So I made a very (kind of scary) script to do exactly what she wanted. There may be some shortcuts I've overlooked, so please let me know if you think there's an easier way.
(This would go in an index-template, where you want your archives to display like this…)
<?
//JUST CHANGE THE VARIABLES BELOW
$db_server = "localhost"; //probably don't need to change this
$db_name = "mt-database-name";
$db_username = "db-username";
$db_password = "db-password";
$pathtoarchives = "http://www.YOURDOMAIN.com/archives/";
$extname = ".php";
$blogid = "1"; //what's your mt blog id for this blog?
///////////////////////////////////////////////////
//connect to database
//get 6mos ago
$today = getdate();
$this_month = $today['mon'];
$this_day = $today['mday'];
$this_year = $today['year'];
if ($this_month == "1") {
$last_month = "7";
$this_year = $this_year-1;
} else if ($this_month == "2") {
$last_month = "8";
$this_year = $this_year-1;
} else if ($this_month == "3") {
$last_month = "9";
$this_year = $this_year-1;
} else if ($this_month == "4") {
$last_month = "10";
$this_year = $this_year-1;
}else if ($this_month == "5") {
$last_month = "11";
$this_year = $this_year-1;
}else if ($this_month == "6") {
$last_month = "12";
$this_year = $this_year-1;
} else {
$last_month = $this_month-6;
}
if ($this_day < 10) {
$this_day = "0".$this_day;
}
if ($last_month < 10) {
$last_month = "0".$last_month;
}
$sixmosago = $this_year."-".$last_month."-01 00:00:00";
$db = mysql_pconnect("$db_server","$db_username","$db_password")
or die("Could not connect");
mysql_select_db("$db_name");
$queryA = sprintf("SELECT entry_id, entry_title, entry_created_on, entry_blog_id FROM mt_entry WHERE entry_blog_id='%s' and entry_created_on > '%s' ORDER BY entry_created_on DESC", $blogid, $sixmosago);
$resultA = mysql_query($queryA);
$numresults = mysql_num_rows($resultA);
for ($i = 0; $i <$numresults; $i++) {
$row = mysql_fetch_array($resultA);
$entrydate = getdate(strtotime($row['entry_created_on']));
$entrymonth = substr ($entrydate['month'], 0,3);
if ($entrydate['mday'] < 10) {
$entryday = "0".$entrydate['mday'];
} else {
$entryday = $entrydate['mday'];
}
$entryyear = substr ($entrydate['year'], 2,2);
if (!isset($lastround)) {
$lastround = "";
}
if ($lastround != $entrymonth) {
echo "<br>".$entrydate['month']." ".$entrydate['year']."<br>";
}
echo $entryyear." ".$entrymonth." ".$entryday.": ";
echo "<a href='".$pathtoarchives.str_pad($row ['entry_id'],6,"0",STR_PAD_LEFT).$extname."'>".stripslashes($row['entry_title'])."</a>";
echo "<br>";
$lastround = $entrymonth;
}
mysql_close($db);
?>
<br>
<MTArchiveList archive_type="Monthly">
<?
if (strtotime("<$MTArchiveDate format="%B %e, %Y %I:%M %p"$>") >strtotime($sixmosago)) {
// do nothing
} else {
$checkdouble = $entrydate['month']." ".$entrydate['year'];
if ($checkdouble == "<$MTArchiveDate format="%B %Y"$>") {
//do nothing
} else {
?>
<a href="<$MTArchiveLink$>"><$MTArchiveDate format="%B %Y"$></a><br>
<?
}
}
?>
</MTArchiveList>