Don’t wanna see you code something up that has been done.
funny but I already did XD
/**
* wp_latest_posts
* @param int $limit number of posts to get
* @param string $fields the fields to fetch
* @param string $blog_db the wordpress database name
* @param string $blog_prefix the wordpress table prefix
*/
function wp_latest_posts($limit,$fields='<code>user_nicename</code>,<code>wp</code>.<code>ID</code>,<code>post_author</code>,<code>post_title</code>,<code>post_name</code>,<code>post_content</code>,<code>post_date</code>',$blog_db=NULL,$blog_prefix='wp_') {
static $blog_sql_format='
SELECT <code>blog_id</code>
FROM <code>%s</code>.<code>%sblogs</code>
ORDER BY <code>last_updated</code> DESC
LIMIT %u
';
static $sql_format='
(
SELECT %s
FROM <code>%s</code>.<code>%s%sposts</code> AS <code>wp</code>,<code>%s</code>.<code>%susers</code> AS <code>wu</code>
WHERE
<code>post_status</code>="publish"
AND <code>post_type</code>="post"
AND <code>wp</code>.<code>post_author</code>=<code>wu</code>.<code>ID</code>
ORDER BY <code>post_date</code> DESC
LIMIT 1
)
';
if (empty($blog_db))
$blog_db=wordpress_db();
$blog_sql=sprintf($blog_sql_format,$blog_db,$blog_prefix,$limit);
$blogs=queryToArray($blog_sql);
$post_queries=array();
foreach ($blogs as $blog) {
$post_queries[]=sprintf(
$sql_format,
$fields,
$blog_db,
$blog_prefix,
$blog->blog_id!=1 ? $blog->blog_id.'_' : '',
$blog_db,
$blog_prefix
);
}
$post_queries=implode(' UNION ',$post_queries);
$sql="
SELECT *
FROM
(
$post_queries
) as <code>latest_posts</code>
ORDER BY
<code>post_date</code> DESC
";
return queryToArray($sql);
}
oops my backticks are everywhere and I can’t see a preview button I’ll try to post it first…
edit: lol all my backticks are converted to < code > </ code> I dunno how to fix that
One weakness of this code is, it can only show one post per blog, therefore if blogger1 has 2 posts that is newer than blogger2’s latest post, they would both show but only one post from blogger1 will show.
And hmmm some of the functions in there are on our company functions so if someone might wanna use this you need to replace those wordpress_db(), queryToArray()
Thanks for the reply again, I’ll check those plugins and gather some ideas to improve this on the future, and Why I did that is because we are using the latest posts on a non wordpress page and <div>’s would be preferrable than
< li >’s (saw this on a plugin earlier)