Are you running more than one blog from your copy of MT? Would you like to have a list of the latest entries in the order they've been updated? The solutions in the past have required you to add a new template to each blog and then use PHP to order them [Brenna's PHP ordered updates thread]. Since I'm already doing something similar with my portal page [PHP portal tutorial], I didn't really want to add another template to each blog every time besides the one I already use in my portal.
With the advent of the MySQL version of MT, its possible to connect directly to the database, and so I am sharing the code I'm using to make a "latest updates" list for my blogs.
The connection info that I use can be gotten from the MySQL Author Archives post.
You'll want to customize the connection info include path, and decide which blogs you are wanting to add in the list. Since I have multiple testing blogs I went through and specified which ones were important to this list. (You can get the blog id by getting into your MT and hovering over the links in the Main Menu – you'll see a blog_id=number at the end of each link.)
The script will go through and get the most recent entry from each blog, as well as the blog name, description, and URL. Then it saves each piece of info and sorts it by the date created. So the most recent entry is on the top. Some of this framework was helped straighten out by my husband!
You can see it in action on my default (red/black) and grunge skins of kadyellebee.com.
<?
//connection info
include ("/home/USERNAME/public_html/PATHTO/connect.php");
//for each of the selected blogs (2, 3, 4, 5, 8, 10, and 14) in mt_blog, find and display in descending order the most recent post in mt_entry.
$alldata = array();
$alldates = array();
$blogcount=0; // keep track of number of blogs
$blogarray = "SELECT blog_id, blog_site_url, blog_name, blog_description FROM mt_blog WHERE (blog_id = 2) or (blog_id = 3) or (blog_id = 4) or (blog_id = 5) or (blog_id = 8) or (blog_id = 10) or (blog_id = 14)";
$resultblog = mysql_query($blogarray) or die (mysql_error());
while ($rowblog = mysql_fetch_array($resultblog)) {
$burl = ($rowblog['blog_site_url']);
$bname = ($rowblog['blog_name']);
$bdesc = ($rowblog['blog_description']);
$rowarray = "SELECT entry_created_on, entry_id, entry_blog_id FROM mt_entry WHERE (entry_blog_id = (".$rowblog['blog_id'].")) ORDER BY entry_created_on DESC";
$resultid = mysql_query($rowarray) or die (mysql_error());
$count=0;
while ($rowid = mysql_fetch_array($resultid)) {
if ($count>0) { break; } //to ensure that if there are less than 1 posts the blog will not break the query
$maxarray = "SELECT entry_title, entry_id, entry_created_on FROM mt_entry WHERE entry_created_on = '".$rowid['entry_created_on']."' and entry_id = ".$rowid['entry_id']; $resultmax = mysql_query($maxarray) or die (mysql_error());
while ($rowmax = mysql_fetch_array($resultmax)) {
$ids = array($rowmax['entry_id']);
$date = ($rowmax['entry_created_on']);
$title = ($rowmax['entry_title']);
//saves the data int alldata array for use outside of the while loop
$alldates[$blogcount++] = $date;
$alldata[$blogcount++] = array('bname'=>$bname, 'burl'=>$burl, 'bdesc'=>$bdesc, 'ids'=>$ids, 'title'=>$title);
}
$count++;
}
}
array_multisort($alldates, SORT_DESC, $alldata);
for ($i=0; $i<sizeof($alldates); $i++) {
//separate date created on up between year, month, and date
$year[$i] = substr($alldates[$i], 2, 2);
$month[$i] = substr($alldates[$i], 5, 2);
$day[$i] = substr($alldates[$i], 8, 2);
//echo date, linked blogtitle and latest entry title
echo '<div class="update">', $month[$i], $day[$i], $year[$i], ': ';
echo '<a href="', $alldata[$i]['burl'], '" target="_blank" title="', $alldata[$i]['bdesc'], '">', $alldata[$i]['bname'], '</a></div>';
echo '<div class="uptitle">', $alldata[$i]['title'], '</div>';
}
?>
2/5/03: Edited to make sure line breaks were in the script!
I used 2 different classes in my stylesheet to stylelize the listing – update and uptitle. These are the styles as they are used in the default skin on my journal
.update {font-size: 9px; font-style:italic; padding: 1px; background-color:black;}
div.update a {font-style:normal; font-size: 10px;}
.uptitle {background-color:#222222; font-size: 11px; padding-bottom: 5px; padding-right: 3px; padding-left: 3px;}
If you have questions or comments, feel free to post comments – I look forward to hearing them!