An alternative for those not wanting to use WP templates at all. This is simpler although you have to be careful what is being selected is what you want. The example assumes you have PEAR:DB or MDB2 installed but it’s simple to convert to use ‘normal’ PHP mySQL built in commands
/*
* getLatestBlogEntries
* Connects to the WP blog DB and retrieve latest 8 postings
* formatting them in HTML
*
*/
function getLatestBlogEntries() {
$blogSQL = "SELECT * FROM wp_posts
WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 8";
// Connect to db and perform query
$dbBlog = DB::connect(BLOG_DB_DSN, true);
$resBlog =& $dbBlog->query($blogSQL);
// loop through result set building links to blog posts
$html = '<ul>';
while($resBlog->fetchInto($blogEntry, DB_FETCHMODE_OBJECT)) {
$html .= '<li><a>ID.'" title="'.stripslashes($blogEntry->post_title).'">'.$blogEntry->post_title."</a></li>\n";
}
$html .= "</ul>\n\n";
// return resulting unordered list of latest blog entry links
return $html;
}
?>