最近发布的作者列表包括href="author url"和类=“optional"


Recently posted author list including href="author url" and class="optional"

我试图根据最近活跃的用户在Wordpress页面上生成一个作者列表,包括在配置文件链接中的类。目前我得到的是

<div id="personae">
<ul>
<?php
$authors =  array();
$count = 0;
$args=array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
  echo '';
  while ($my_query->have_posts() && $count < 3) : $my_query->the_post();
    $author_id=$my_query->post->post_author;
    $user = new WP_User( $author_id );
    if ( !empty( $user->roles ) && is_array( $user->roles ) && in_array('contributor',$user->roles) || in_array('',$user->roles)) {
      if (!in_array($author_id,$authors)) {
        echo '<li>';
        the_author_meta('title');
        echo ' <a href="#" class="';
        the_author_meta('personaeclass');
        echo '">';
        the_author_nickname();
        echo '</a>';   
        echo '</li>';
        $count++;
        $authors[]=$author_id;
      }
    }
  endwhile;
}
wp_reset_query();  
?>
</ul>
</div>

生成了最近三位作者的近乎完美的代码。

<div id="personae">
<ul>
<li>Editor <a href="#" class="menu-item-1">Name</a></li>
<li>Photographer <a href="#" class="menu-item-2">Name</a></li>
<li>Journalist <a href="#" class="menu-item-3">Name</a></li>
</ul>
</div>

我几乎在那里 我只需要作者的链接是href="作者配置文件url"而不是#。我已经尝试使用the_author_posts_link(");这是有效的,但没有办法有class="内的链接,我也需要应用。

有什么建议来解决这个问题吗?谢谢! !

功能get_the_author_link()应该可以工作。所以

echo ' <a href="#" class="';

将成为

echo ' <a href="'. get_the_author_link() . '" class="';

编辑:我的道歉,以上将得到作者的网站url try:

get_author_posts_url($author_id)

试试这个,

<div id="personae">
<ul>
<li>Editor <a href="<?php echo get_author_posts_url(  $author_id, get_the_author_meta( 'user_nicename', $author_id ) ); ?>" class="menu-item-1"><?php echo get_the_author_meta( 'display_name', $author_id ); ?></a></li>
</ul>
</div>
参考

  • get_author_posts_url
  • get_the_author_meta