按最新帖子列出排名靠前的作者

时间:2012-01-30 作者:Nina

我试图显示最近帖子列出的顶级作者的表格格式。它应该显示作者、头像、日期和帖子标题(带有链接)。

我已经列出了头号作者和头像。但它不会显示帖子的标题或正确的日期。

以下是我目前掌握的情况:

$uc=array();
$blogusers = get_users_of_blog();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$userpost = get_posts(\'showposts=1&author=\'.$bloguser->user_id);
$uc[$bloguser->user_id] = \'\';
if ($userpost) {
  $uc[$bloguser->user_id]=$userpost[0]->post_date;
}
}
arsort($uc);
$i = 0;
foreach ($uc as $key => $value) {

$user = get_userdata($key);
$post_id= $user->postID;
$post_title= $user->post_title;
$post_date= $user->post_date;
$post_count = get_usernumposts($user->ID);
if ($post_count && $i < 10) {
  $author_posts_url = get_author_posts_url($key);      
  ?>
  <table width="280" border="0" cellspacing="0" cellpadding="5">
                  <tr> 
                      <td width="15%"> <img src="<?php bloginfo (\'template_directory\'); ?>/images/authors/<?php print $user->user_login; ?>.jpg" onerror= "this.src=\'<?php bloginfo (\'template_directory\'); ?>/images/authors/default.jpg\'" width="45" height="50"></td>
                      <td width="85%" align="left">
                          <div class="sidebar_post"><?php printf ("<a href=\\"index.php?p=%s\\">%s</a></li>", $post_id,$post_title)?><br></div>
                          <div class="sidebar_author">By <?php print $user->display_name;?><br></div>
                          <div class="sidebar_postdate">Posted <?php the_time(get_option(\'date_format\'));?></div>
                      </td>
                  </tr>
                    <tr>
                      <td colspan="2"><hr></td>
                  </tr>
                </table>
 <?php    }
 $i++;
}
}

2 个回复
最合适的回答,由SO网友:Nina 整理而成

更新:为了解决这个问题,我把它改了。这可能不是一个理想的解决方案,但它满足了我的需要。

            // Selects from tables wp_users and wp_posts, selecting published posts and ordering by its post_date, limited to 10
            $querystr = "SELECT * from wp_users, wp_posts WHERE wp_users.ID = wp_posts.post_author AND wp_posts.post_type = \'post\' AND wp_posts.post_status = \'publish\' ORDER BY wp_posts.post_date DESC LIMIT 10";

              $news=$wpdb->get_results($querystr, OBJECT);

              foreach($news as $np)
              {
                $authorID = $np->authorID;
                $author_nickname = $np->user_login;
                $author_displayName = $np->display_name;
                $author_niceName = $np->user_nicename;
                $post_id= $np->postID;
                $post_title= $np->post_title;
                $post_date= $np->post_date;

SO网友:kaiser

执行WP_User_Query 然后检查结果:

$wp_user_search = new WP_User_Query( array( 
    \'role\' => \'author\', 
    \'fields\' => \'all_with_meta\' 
) );
$editors = $wp_user_search->get_results();
echo \'<pre>\';
print_r( $editors );
echo \'</pre>\';

结束

相关推荐

Remove author archive

我正在使用wordpress作为CMS。工作人员中的各种用户都会撰写文章,并手动将其合并到页面中。就外部世界而言,这只是一堆静态页面。我想删除所有作者、类别等概念。我注意到我可以浏览到域。com/author/userName并查看作者存档。如何禁用此功能?我想退货404。