Created
October 22, 2010 19:09
-
-
Save jbynum/641184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$show = 10; # The number of posts to display on this page | |
if (isset($_GET['pageID'])) | |
{ | |
$pageID = $_GET['pageID']; | |
} else { | |
$pageID = 1; | |
} | |
$startID = (($pageID-1)*$show)+1; | |
$endID = $startID+($show-1); | |
//echo "Showing posts $startID - $endID starting at $pageID"; | |
#globalize wpdb | |
global $wpdb; | |
$doc_user = get_post_meta($post->ID, 'wp_user_name', true); | |
$doc = $wpdb->get_results("SELECT * FROM wp_users WHERE user_login = '$doc_user' "); | |
# get an array containing all blog ids and count how many there are | |
$result = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND blog_id != '1'"); | |
$count = $wpdb->num_rows; | |
# compile a query for all posts from all blogs and order with most recent first | |
$i=0; | |
foreach ($result as $blog_id) { | |
$i++; | |
if ($i < $count) { | |
$post_query .= "SELECT post_date, UNIX_TIMESTAMP(post_date) AS date, post_title, guid, post_content, post_author, display_name FROM wp_".$blog_id."_posts LEFT JOIN wp_users ON wp_".$blog_id."_posts.post_author = wp_users.ID WHERE post_status = 'publish' AND post_type = 'post' UNION ALL "; | |
}else{ | |
$post_query .= "SELECT post_date, UNIX_TIMESTAMP(post_date) AS date, post_title, guid, post_content, post_author, display_name FROM wp_".$blog_id."_posts LEFT JOIN wp_users ON wp_".$blog_id."_posts.post_author = wp_users.ID WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date "; | |
} | |
} | |
//echo "<!-- $post_query -->"; | |
# run the query | |
$post_result = $wpdb->get_results($post_query); | |
$x=0; | |
# process and format each post from the query result | |
foreach ($post_result as $post_row) { | |
# process post title and link | |
$post_title=$post_row->post_title; | |
$post_url=$post_row->guid; | |
# process time: determine how long ago the post was made and format accordingly | |
$post_date=$post_row->date; | |
$period=time()-$post_date; | |
$period = date('F d, Y h:i A', $post_date); | |
$display_name=$post_row->display_name; | |
if ($doc[0]->display_name != $display_name ) continue; | |
# output html | |
//echo "<h2><a href=\"$post_url\">$post_title</a></h2>\n<p>$period by $display_name</p>\n<p>$post_content</p>\n\n"; | |
echo "\n\t\t\t<div class=\"docPost\">\n\t\t\t\t<div class=\"title bluehighway\"><a href=\"$post_url\">$post_title</a></div>\n\t\t\t\t<div class=\"docpostmeta\">Posted by <span class=\"post-author\">$display_name</span> on $period</div>\n\t\t\t\t</div><hr />"; | |
$x++; | |
if ($x > 9) break; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment