<?php
/*
Template Name: Realty Test
Classes that power the front page of the realtyblogging site, and the recent posts page.
*/
class realty_front {
// this handles grabbing the newest (n) posts from all the blogs on the system and displaying them.
function tables() {
global $wpdb, $wpmuBaseTablePrefix;
$select = $wpdb->get_results( "SELECT blog_id FROM $wpdb->blogs WHERE public = 1 ORDER BY blog_id ASC" );
$num = count ( $select );
foreach ( $select as $table ) {
$return = $wpmuBaseTablePrefix . $table->blog_id . '_posts';
$i++;
if ( $i == $num ) {
//echo '';
$return .= '';
} elseif ( $i == $num -1 ) {
//echo ',';
$return .= ',';
} else {
//echo ',';
$return .= ',';
}
}
return $return;
}
function recent_posts($limit='20') {
global $wpdb, $wpmuBaseTablePrefix;
echo '<h1>Recent Posts</h1>';
// then we take our new found Id's, convert them to table names and query for our post content
$content = $wpdb->get_results( "SELECT * FROM " . realty_front::tables() . " ORDER by 'post_date' DESC LIMIT $limit" );
foreach ( $content as $data ) {
$author = $wpdb->get_row( "SELECT * from $wpdb->users WHERE ID = $data->post_author" );
echo '<div>';
echo '<h2><a href="' . $data->guid . '">' . $data->post_title . '</a></h2>';
echo '<small><h4>Contributed by <a href="' . $author->user_url . '">' . $author->display_name . '</a> posted on ' . mysql2date('F j, Y, g:i a', $data->post_date_gmt) . '</h4></small>';
echo $data->post_content;
echo '<p><small><a href="' . $data->guid . '">Permalink</a> | <a href="' . $data->guid . '#comments">Comments</a></small></p>';
echo '</div>';
}
} // and we're done with this bit.
function paged_vars() {
$rowsPerPage = 5;
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page'])) {
$pageNum = $_GET['page'];
}
}
function list_posts($num) {
global $wpdb, $pageNum, $rowsPerPage, $content;
$count = count($content);
echo 'The number is ' . $count;
}
// And now we find the newest post by post_date from all of our 'featured' bloggers
function featured_post() {
global $wpdb, $wpmuBaseTablePrefix;
// first we grab the featured authors, if there are any from the database
//$authors = get_option( 'featured_authors' );
$authors = 'wp_1_posts,wp_5_posts,wp_6_posts';
// then we pass that value on to our query so that we can get the most recently published post from these authors
$content = $wpdb->get_results( "SELECT * FROM $authors ORDER BY 'post_date' DESC LIMIT 1" );
echo '<h1>Featured Post</h1>';
// the go ahead and display that post
foreach ( $content as $data ) {
$author = $wpdb->get_row( "SELECT * from $wpdb->users WHERE ID = $data->post_author" );
echo '<div>';
echo '<h2><a href="' . $data->guid . '">' . $data->post_title . '</a></h2>';
echo '<small><h4>Contributed by <a href="' . $author->user_url . '">' . $author->display_name . '</a> posted on ' . mysql2date('F j, Y, g:i a', $data->post_date_gmt) . '</h4></small>';
echo $data->post_content;
echo '<p><small><a href="' . $data->guid . '">Permalink</a> | <a href="' . $data->guid . '#comments">Comments</a></small></p>';
echo '</div>';
}
}
}
// here we get the id of the blog we need to query against, we then pass it on to the $content query.
//$user_info = $wpdb->get_row( "SELECT meta_value FROM user_meta WHERE user_id = $id AND meta_key = 'primary_blog'" );
?>
<?php
realty_front::featured_post();
echo '<hr />';
realty_front::recent_posts();
?>