Who We Are
bmk
girlie
kristine
Search



Notify List
Let us keep you posted on new entries! Join the notify list!
Blog Status
14 entries
146 comments
12.06.04 11:44 am last update
last 50 referrers

Listed on BlogShares
Syndication
link to us!

virtual venus

virtual venus: MT Wiki
Powered By
because weblogs need love too
Sunday, July 13, 2003
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 I have more than one blog on my site, I wanted entries from all of them to be considered, rather than having to post in a single blog; and I wanted them all merged together in one list that I could use on a special Blogathon page, where sponsors could track my progress throughout the evening without bouncing all over my site.

Of course, the first people I looked to were my Venus sisters. Kristine's Multiple Blog Updates List, and Brenna's PHP Ordered Updates gave me a starting point, but the theme common to these methods was that they returned only a single most recent entry from each blog, rather than the most recent N entries from across all blogs.

So I set out to get out what I wanted, hoping to also learn a little more about MySQL and PHP along the way.



First Method


    Required:
  • MySQL database option in Movable Type
  • ability to use PHP on your site

This approach grabs certain entry and blog information, and displays a simple list of the last 10 entries in the specified blogs.

Here is the core code I used in my index template:

<?
//connection info
include ("/FULL/PATH/TO/connect.php");

$entries = mysql_query("SELECT e.entry_created_on, e.entry_blog_id, e.entry_id, e.entry_title, SUBSTRING_INDEX(entry_text, ' ', 25) AS excerpt, b.blog_id, b.blog_site_url, b.blog_name, b.blog_description FROM mt_entry e, mt_blog b WHERE (e.entry_blog_id = 2 OR e.entry_blog_id = 3 OR e.entry_blog_id = 7 OR e.entry_blog_id = 8 OR e.entry_blog_id = 13 OR e.entry_blog_id = 16 OR e.entry_blog_id = 17) AND e.entry_status = 2 AND e.entry_blog_id = b.blog_id ORDER BY e.entry_created_on DESC LIMIT 10");

while($row = mysql_fetch_array($entries)) {
while (list($key,$val) = each($row)) {$$key = $val;}
$date = date("F d, Y h:i a", strtotime($entry_created_on));
$body = strip_tags($excerpt);
echo "<div class=\"blogbody\"><h3 class=\"title\">$entry_title</h3><br />\n";
echo "$body<br /><br /></div>\n";
echo "<h2 class=\"date\">posted in <a href=\"$blog_site_url\">$blog_name</a> on $date</h2>\n";
echo "<hr class=\"ruler\">\n";
}
?>

Kristine gave me this piece of code to get an excerpt for each entry:

SUBSTRING_INDEX(entry_text, ' ', 25) AS excerpt

Replace 25 with the number of words you want to display as the excerpt.

To select the specific blogs from which to pull data, use

e.entry_blog_id = #

repeated for each blog, replacing # with the blog ID.

The benefit of this method is that no rebuilding is required to update the merged listing, because you're connecting straight to the database to grab the latest entries.



Second Method


So why didn't I stick with the first method? Because it wasn't flexible enough for my needs.

First, each of my blog's entries require unique handling. My Bookmarks blog is a collection of links, inspired by maikimo.net, and the entry body is simply a URL. I wanted it to be clickable, just like in the original blog. My Journal now has restricted access posts, so I might not always want the entry body showing up on the list.

Second, I wanted to link to the actual entries, not just the blogs they appeared in - and my Archive File Templates are different in each blog, so trying to construct a common linking structure would have been painful (oh, how I wish permalinks were stored in the MT database!).

I shifted my code to the SQL plugin (the query is a great deal simpler now, because using the plugin permits you to also make use of the other MT tags) and bumped up the number of entries to 15:

<MTSQLEntries unfiltered="1" query="SELECT e.entry_id FROM mt_entry e WHERE (e.entry_blog_id = 2 OR e.entry_blog_id = 3 OR e.entry_blog_id = 7 OR e.entry_blog_id = 8 OR e.entry_blog_id = 13 OR e.entry_blog_id = 16 OR e.entry_blog_id = 17) AND e.entry_status = 2 ORDER BY e.entry_created_on DESC LIMIT 15">

<h3 class="title"><MTEntryTitle></h3>
<$MTEntryBody convert_breaks="0"$>
<MTEntryIfExtended>
<a href="<MTEntryPermalink>">[more]</a>
</MTEntryIfExtended>
<h2 class="date">posted in <a href="<MTBlogURL>"><MTBlogName></a> on <MTEntryDate format="%B %d, %Y" lower_case="1"></h2>

</MTSQLEntries>

So now I had the basic data that I wanted; the only thing left was customizing on a per-blog basis, and that's where Compare and FirstNWords helped out.

Here's what the custom code for my Journal entries looks like:

<MTIfEqual a="[MTBlogName]" b="The Girlie Matters">
<h3 class="title"><MTEntryTitle lower_case="1"></h3>
<$MTEntryBody convert_breaks="0"$>
<MTEntryIfExtended>
<MTIfEqual a="[MTEntryCategory]" b="restricted">
<em> (restricted access entry) </em>
</MTIfEqual>
<a href="<MTEntryPermalink>">[more]</a>
</MTEntryIfExtended>
<h2 class="date">
posted in <a href="<MTBlogURL>">journal</a> on <MTEntryDate format="%B %d, %Y" lower_case="1">
</h2>
</MTIfEqual>

And for my Bookmarks entries:

<MTIfEqual a="[MTBlogName]" b="Bookmarks">
<h3 class="title"><a href="<$MTEntryBody convert_breaks="0"$>" title="<$MTEntryExcerpt$>"><MTEntryTitle lower_case="1"></a></h3>
<em><MTEntryExcerpt></em>
<MTEntryIfExtended>
<MTEntryMore>
</MTEntryIfExtended>
<h2 class="date">
posted in <a href="<MTBlogURL>">bookmarks</a> on <MTEntryDate format="%B %d, %Y" lower_case="1">
</h2>
</MTIfEqual>

I repeated similar code for my other blogs (note that each set of MTIfEqual containers goes before the </MTSQLEntries> tag). I chose to use MTBlogName instead of MTBlogID in the MTIfEqual statements because it made it easier for me to keep track of which blog the statement was for.

If you want to see what the final code looked like, I've posted it here in the Demos blog.

And you can view the results on my portal page (design still in progress).

There's one element left - getting the page to rebuild automatically when entries are posted to the various blogs. (See Update below.)

I have a Site Info blog, which is really just an interface for maintaining non-blog areas of my site via MT (there are no entries, and all the templates are set to Rebuild: No). Since I consider the portal page to be a site feature, this blog seemed to be the logical place for it. So now it's the only template which is set to Rebuild: Yes.

Next, I added a category called "portal" to the Site Info blog, and edited its attributes to Accept Incoming Trackback Pings. I copied the assigned Trackback URL, and pasted it in the Blog Configuration | Preferences | Publicity section of each blog which will be updating to the list. Now, whenever I post an entry to any of these blogs, the resulting ping to the Site Info portal category forces the portal page to be rebuilt.

(One thing I noticed when testing the ping is that I got an error unless I enabled Category Archiving in the Site Info blog. I was reluctant to do this at first, because I didn't want to generate an actual category page in the blog. However, with no entries, no category page is published, so it was a moot issue.)



After all of this thinking, I realized I may be too tired to participate in Blogathon after all. =)



Update 07.25.03: Oops. Guess what? There's a difference between a Trackback ping and a weblogs.com style ping, so that whole thing about getting the page to rebuild automatically doesn't work. That's the reason I got the error on my ping attempt, but because I tested the second ping via the Edit Entry screen, I was fooled into thinking it would work both ways. (Can you tell how infrequently I've made use of Trackback?)

Suggested solutions (so far):

1) Setting up a category in each blog that will ping the portal category in the Site Info blog, and assign each entry to that category (but I don't want this category to display on the blogs where it says "posted in blah blah category, so that's out for me).

2) Set up your existing categories to ping the portal category (okay, will I get multiple pings for entries posted to multiple categories? If so, Brenna's Remove Pings will help keep those cleaned out).

3) Mark's PingRebuilder CGI Script

4) Manually rebuilding the portal page anytime I post to one of the other blogs.

5) A cron job using MT-Rebuild.

Will add another update once I've settled on a solution.


Comments: 4

I bet you could even use this idea to create a merged blog feed so that people could read the info from your multiple blogs all in one place :) It might be a fun thing for me, with kadyellebee and lovelinks and collectics and maybe other blogs I have - I don't post to them as frequently as kadyellebee, so people wouldn't normally subscribe to those feeds. But this would be a cool way to integrate them! :)

by kristine at 08:55 PM on 07.13.03

david raynes also has a plugin that might work the same way. gotta admit i haven't read this entire entry so not too sure, but it's worth a look at.

http://www.rayners.org/archives/cat_mt_plugins.php#ent000131

by patricia at 05:11 PM on 07.14.03

The reason I didn't consider WholeSystem (and I should have mentioned that I did consider it), was because I only wanted to include specific blogs, not all blogs in my system.

GlobalListings, on the other hand, would have been a logical choice - but I had a secondary goal apart from just getting the results I wanted - I also had the desire to actually learn a little about MySQL and PHP. Using the SQL plugin vs. using GlobalListings gave me the opportunity to do that.

In the end, the bulk of the code I used would have remained the same, regardless of which plugin I used to actually grab the entries.

by girlie at 05:43 PM on 07.14.03

I would feel a lot safer if the index file was password protected, kinda like someplace where you have to login you know !

by Arvind Satyanarayan at 12:27 PM on 09.09.03
Comments are closed on this entry
More Entries

Copyright © Virtual Venus