I used this to get a feed of recent blog posts on my home page if this works for you:
<?php
/**************MOST RECENT BLOG POSTS BOCK******************/
$db_prefix = "wp"; //this is your database prefix, if your first user has wp_1_posts, then your prefix is "wp"
$howmany = 10; //how many rows of results do you want back?
$width = 60; //how wide do you want your rows?
/********************************************************************/
//i first tried pulling in every blog post by user, but then i lost all information about the default blog address. this became important when a guest
//user posted on somebody else's blog, at which point i'd find the user's default blog address and contstruct a wrong URL.
//define('WP_USE_THEMES', true);
require('./wp-blog-header.php');
function get_path($userID){
global $wpdb;
$req = "select path from wp_blogs where post_parent='" . $userID . "';";
//echo $req;
$res = $wpdb->get_results($req);
$post['path'] = $res[0]->path;
return $post;
}
function bigcmp($a, $b)
{
if ($a['datetime'] == $b['datetime']) {
return 0;
}
return ($a['datetime'] < $b['datetime']) ? 1 : -1;
}
$request = "select * from wp_blogs;";
$result = $wpdb->get_results($request);
//print_r($result);
$i = 0;
foreach($result as $v1){
//get the blog name from each user and save it as $blogname to use in the next foreach
$db_table = $db_prefix . "_" . $v1->blog_id . "_options" ;
$requestx = "select option_value from " . $db_table . " where option_name='blogname' and option_id=2;";
$resultx = $wpdb->get_results($requestx);
$blogname = $resultx[0]->option_value;
//for each user get all their posts
$db_table = $db_prefix . "_" . $v1->blog_id . "_posts" ;
$request2 = "select * from " . $db_table . ";";
$result2 = $wpdb->get_results($request2);
$domain = $v1->domain;
$path = $v1->path;
//print_r($result2);
//list every post in the system
foreach($result2 as $v2){
//this part takes the date and breaks it up into year, month, day, but first save the date to use it
$array = explode(" ", $v2->post_date);
$array = explode("-", $array[0]);
$y = $array[0]; $m = $array[1]; $d = $array[2];
$allposts[$i]['datetime'] = $v2->post_date;
$string = $y . "/" . $m . "/" . $d . "/" . $v2->post_name;
$allposts[$i]['title'] = $v2->post_title;
$allposts[$i]['path'] = $v1->path;
$post_type = $v2->post_type;
/*this part gives you the post/page format, and guid URL if it's a guest poster */
//if guest user ID?
if($v2->post_type == attachment) {
}
else {
if($v2->guid !== NULL) {
$allposts[$i]['fullurl'] = $v2->guid;
$allposts[$i]['blogname'] = $blogname;
}
$i++;}
}
}
usort($allposts, "bigcmp");
//get total number of posts
$today = date('m-d-Y');
$totalposts = count($allposts);
echo '
';
for($i = 0; $i < $totalposts && $i < $howmany; $i++){
if ($allposts[$i]['post_type'] == attachment)
{$howmany++;}
else {
$dateposred = explode(" ", $allposts[$i]['datetime']);
$dateposred = explode(":", $dateposred[1]);
$dateposted = explode(" ", $allposts[$i]['datetime']);
$dateposted = explode("-", $dateposted[0]);
$dateposted = $dateposted[2] . "-" . $dateposted[1] . "-" . $dateposted[0] . " o " . $dateposred[0] . ":" . $dateposred[1] . ":" . $dateposred[2];
//make the length as short as the implementer wants it
$url = substr($allposts[$i]['title'], 0, $width);
$author = "Published " . $dateposted;
$author = substr($author, 0, $width);
$blogname = $allposts[$i]['blogname'];
$blogname = substr($blogname, 0, $width);
$asd = strlen($allposts[$i]['fullurl']);
$dsa = strlen("");
if ($dsa !== $asd) {
echo '
- <a href="' . $allposts[$i]['fullurl'];
echo '" title="';
echo $author;
echo '">';
echo $url;
echo '';
echo '
';
}
else {$howmany++;}
}
}
echo '
';
/*********************MOST RECENT BLOG POSTS END******************************/
?>
you can see it in action at http://megablogs.net
I hope this helps, cos i spent ages looking for something like that and actually getting it working.
I am now looking for a piece of code that will allow me to list Most recent members and most recent blogs on my home page. so if you come across something it would be good if you could pass it on to me.
Thanks
iamsgf