我试图显示最近帖子列出的顶级作者的表格格式。它应该显示作者、头像、日期和帖子标题(带有链接)。
我已经列出了头号作者和头像。但它不会显示帖子的标题或正确的日期。
以下是我目前掌握的情况:
$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++;
}
}
最合适的回答,由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;