So. I made a part of it, and I think I should post it here :)
This is a part of index.php. It show a post per each author by default, or if a post is selected it shows the post centent and 2 post before it.
if(!is_single()) {
//get all users, iterate through users, query for one post for the user,
//if there is a post then display the post title, author, content info
$blogusers = get_users('blog_id=1&orderby=nicename&role=author');
//print_r($blogusers);
//die();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$args = array(
'author' => $bloguser->ID,
'showposts' => 1
);
$my_query = new WP_Query($args);
//print_r($my_query);
//die();
if( $my_query->have_posts() ) {
// $user = get_userdata($bloguser->ID);
// echo 'This is one post for author with User ID: ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname;
while ($my_query->have_posts()) : $my_query->the_post();
get_template_part('content');
endwhile;
}
}
}
} else {
if(have_posts()) {
while ( have_posts() ) : the_post();
get_template_part('content');
$author_ID = get_the_author_meta('ID');
$datetime = get_the_date('Y-m-d H:i:s');
endwhile;
wp_reset_postdata();
//echo $datetime;
$args = array(
'author' => $author_ID,
'showposts' => 2
);
function filter_where( $where = '' ) {
global $datetime;
// posts for March 1 to March 15, 2010
$where .= " AND post_date < '" . $datetime . "'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );
$my_query = new WP_Query($args);
remove_filter( 'posts_where', 'filter_where' );
if( $my_query->have_posts() ) {
// $user = get_userdata($bloguser->ID);
// echo 'This is one post for author with User ID: ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname;
while ($my_query->have_posts()) : $my_query->the_post();
$more = 0;
get_template_part('content', 'special');
endwhile;
}
}
}
About categories, I made one parent category for each author, and show its subcategories.
global $wp_query;
$post = $wp_query->post;
//print_r($wp_query->post);
$categories = get_the_category($post->ID);
$category = isset($categories[0]) ? $categories[0] : 0;
foreach($categories as $c) {
if($c->parent == 0) $category = $c;
}
//print_r($category);
$args = array(
'child_of' => $category->cat_ID,
'hide_empty' => 0,
'pad_counts' => true
);
$categories = get_categories( $args );
print_r($categories);
For author archives, I customized the wordpress function wp_get_archives()
like so:
/* Replace old $defaults */
$defaults = array(
'type' => 'monthly', 'limit' => '',
'format' => 'html', 'before' => '',
'after' => '', 'show_post_count' => false,
'echo' => 1, 'order' => 'DESC',
'post_author' => '',
);
/* ... */
/* And the $where filter */
$where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'" . ($post_author != '' ? ' AND post_author = ' . $post_author : ''), $r );
Maybe there is a better solution, but I use this.
And at the end, recent post of the current author
/* Get posts related to curent post author */
function get_related_author_posts($number = 5) {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => $number ) );
$output = '<ul>';
foreach ( $authors_posts as $authors_post ) {
$output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
}
$output .= '</ul>';
return $output;
}