scriptygoddess

13 Sep, 2002

Multiple blog Updates List

Posted by: kristine In: MT hacks

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!

22 Responses to "Multiple blog Updates List"

1 | Mariann

September 14th, 2002 at 7:49 am

Avatar

Thanks for sharing this with the blogging community… I've been experimenting with the PHP option, but I'm really curious about this one, too!

Now if I could get my skins to cooperate, I'd be moving along quite nicely. :)

2 | kathi

December 9th, 2002 at 2:09 pm

Avatar

Thanks so much for this code!! I needed to add excerpts from the main entry text for the site at http://www.blogatorium.com/ so I thought I'd post what I did in case anyone else could use it.

Added a line right under $blogcount to define a word space:

$aspace=" "; // define single word space

Added the entry_text field to the SELECT statement in $maxarray:

$maxarray = "SELECT entry_title, entry_id, entry_created_on, entry_text FROM mt_entry WHERE entry_created_on = '".$rowid['entry_created_on']."' and entry_id = ".$rowid['entry_id'];

Changed the definition of $text to delete any HTML code and trim the entry_text to a reasonable length:

//trims entry_text to approx 125 chars without breaking last word
$text = substr(strip_tags($rowmax['entry_text']), 0, 125);
$text = substr($text,0,strlen($text)-strpos(strrev($text),$aspace));

Also defined another class (.uptext) in the stylesheet to handle the body text.

3 | gabriel

April 2nd, 2003 at 10:50 am

Avatar

uhm i don't know if this is a bug or what…maybe just my server… I'm using this hack on the default skin on my site… it works fine on the index page but if i click on the most recent entry link I get an error…

Warning: Cannot use a scalar value as an array in /xxx/xxx/xxx/blog-updates.php on line 51

and btw it seems to be working fine on all other pages as well… Any ideas?

4 | Jenni

June 16th, 2003 at 9:38 pm

Avatar

Can this be done with out MySQL with just using MT tags? Sort of like it's done with the recent comments code?

5 | Jeff Sisson

August 14th, 2003 at 12:27 am

Avatar

I use this script and I love it, and have been slaving away trying to figure out one thing: how can you limit the most recently updated so that only THE most recently uipdated blog shows? I have been tinkering with limit statements all night to no avail. If someone could help that would rock.

6 | zach

August 18th, 2003 at 2:25 am

Avatar

i love this script it works wonders for my multiple blog setup. my question is .. how do i limit it to only entries that have been set to "publish" and not drafts?

7 | John

October 24th, 2003 at 5:30 pm

Avatar

I have a standard top and bottom 2-window frameset, and need to pass from the top frame a date from a 'SELECT' pulldown containing the dates that exist in a DB table column called SaleDate to the bottom frame which displays all records for the date selected.

I'm drawing a blank on how to pass the date from the top frame to the bottom, as well as having the bottom frame wait long enough for the top to get all the available dates. Unfortunately, the dates will change with the wind (very often) so I can't hard-code a preselected date for the bottom frame to pre-display.

Here's my top frame:
.
.
.
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("MyApp")
RlDateQry = "SELECT Distinct top 50 SaleDate FROM RunLists order by SaleDate desc"
Set RLRs = conn.Execute(RlDateQry)
%>
<form name="topFrame">Select a Sale Date:<select size='1' name="topSelect">
<%
DO WHILE NOT RLRs.EOF
SaleDate = RLRs("SaleDate")
%>
<option value='<%=SaleDate%>'><%=SaleDate%></option>
<%
RLRs.MoveNext
LOOP
RLRs.Close
%>
</select>
</form>

Any ideas on how to pass the date? Can you think of a better way to display this info (instead of frames use divs, or perhaps iframes)?

TIA…

8 | Adam Kalsey

December 10th, 2003 at 2:34 am

Avatar

You could speed this up greatly by writing a single SQL statement that pulls all the info at once. Then use the PHP date() function to format the date when you display it.

The following re-written version of the code uses only one database query, sorts the data at the DB instead of in the code, and uses the IN statement to select a list of which blogs to use.

This will be MUCH faster, especially under a heavy load.

9 | Adam Kalsey

December 10th, 2003 at 2:36 am

Avatar

Whoops. Forgot to entity encode the script…

<?php
//connection info
include ('/home/USERNAME/public_html/PATHTO/connect.php');

//for each of the selected blogs (1,2,3,4,5,6,7,8,9) in mt_blog, find and display in descending order the most recent post in mt_entry.

$blogs = '1,2,3,4,5,6,7,8,9';

$sql = "SELECT entry_title, entry_created_on, entry_id, entry_blog_id, blog_id, blog_site_url, blog_name, blog_description FROM mt_blog, mt_entry WHERE blog_id in ($blogs) AND blog_id = entry_blog_id ORDER BY entry_created_on DESC";
$result = mysql_query($sql) or die ('Bad query');
while ($entry = mysql_fetch_array($result)) {
echo '<div class="update">'. date('F j, Y',strtotime($entry['entry_created_on'])). ': ';
echo "<a href=\"{$entry['blog_site_url']}\" target=\"_blank\" title=\"{$entry['blog_description']}\">{$entry['blog_name']}'</a></div>";
echo "<div class=\"uptitle\">{$entry['entry_title']}</div>";
}

mysql_free_result($result);
mysql_close();
?>

10 | Greg

February 7th, 2004 at 6:19 am

Avatar

Thanks for your excellent help, I have implemented some of the ideas into a portal page, to be found at http://www.aboutthisboy.co.uk/portal/index.php. Needs more work, but some great ideas much appreciated.
Cheers.
Greg

11 | Matt

April 19th, 2004 at 11:40 am

Avatar

I hope this isn't an inappropriate forum to ask this:

Is there a way to have this script display the most recently updated blogs, without repeat entries? A couple of my blogs update more frequently than others, so the list gets "stacked" in favor of one blog.

My basic goal is to use this script to not get the three most recent entries from my blogs, but the names and URLs of the three most recently updated blogs.

For what it's written to do, though, I had no problems. Worked like a charm! I'm rather thrilled I finally switched the DBs over from Berekly to MySQL.

12 | kadyellebee

September 13th, 2002 at 4:35 pm

Avatar

Multiple blog Updates List
I finally got a chance to put together my code for the Multiple blog Updates List like I'm using on

13 | In Reflection

November 20th, 2002 at 8:55 am

Avatar

Updates
Managed to put on script found at Scriptygoddess – latest updates. If you have several blogs it is cool thing

14 | MT Plugin Directory

December 5th, 2002 at 7:10 pm

Avatar

OtherBlog
Not Yet Implemented. Alternative to PHP or SSI options. Some of those other previous recommended options – ScriptyGoddess – MySQL

15 | MT Plugin Directory

January 2nd, 2003 at 10:52 pm

Avatar

Whole System
Works similar to Blog Updates for Multiple blogs.

16 | Life In the Dumpster

June 3rd, 2003 at 12:15 pm

Avatar

e53.org
I recently finished the new main page for e53.org. It now lists all of the blogs in order of most recently updated and also includes an excerpt from the recent post. Thanks for scriptygoddess supplying the code.. everything worked perfect…

17 | Life In the Dumpster

June 3rd, 2003 at 12:17 pm

Avatar

e53.org
I recently finished the new main page for e53.org. It now lists all of the blogs in order of most recently updated and also includes an excerpt from the recent post. Thanks for scriptygoddess supplying the code.. everything worked perfect…

18 | Virtual Venus

July 13th, 2003 at 10:54 am

Avatar

Multiple Blogs – Merged Entries List
I was inspired to figure this out while toying with the notion of participating in this year's Blogathon. Given that…

19 | lonita.links

March 7th, 2004 at 7:22 pm

Avatar

Scripty Goddess: Multiple Blog Updates
Scripty Goddess: Multiple Blog Updates…

20 | ChaosKitten

April 20th, 2004 at 11:08 am

Avatar

MT Hacks
So the biggest hacks I'm using are the sideblog (that thing over there on the right) and the updated list on the front page. That being said, there's no real way to import entries/comments from pM yet, which is disappointing……

21 | Code Novice

April 29th, 2004 at 11:55 pm

Avatar

Bookmarks Abound
[Edited to add my apologies if I pinged your entry…

22 | Code Novice

April 29th, 2004 at 11:57 pm

Avatar

Bookmarks Abound
[Edited to add my apologies if I pinged your entry…

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