所以我做了一部分,我想我应该把它贴在这里:)这是索引的一部分。php。默认情况下,它会按每个作者显示一篇文章,或者如果选择了一篇文章,则会显示文章的百分位和前面的两篇文章。
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;
}
}
}
关于类别,我为每个作者创建了一个父类别,并显示其子类别。
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);
对于作者档案,我定制了wordpress函数
wp_get_archives()
像这样:
/* 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 );
也许有更好的解决方案,但我用这个。
最后,当前作者的最新帖子
/* 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;
}