WordPress调用最新注册的用户并显示在侧边栏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
    *WordPress 获取最新注册的用户
*/
function Bing_recently_registered_users(){
    global $wpdb;
    $recentusers = '<ul class="recently-user">';
    $usernames = $wpdb->get_results( "SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY ID DESC LIMIT 5" );//修改最后的 5 为你要显示的用户的数量
    foreach( $usernames as $username ){
        if( !$username->user_url ) $recentusers .= '<li>' . get_avatar( $username->user_email, 45 ) . $username->user_nicename . '</a></li>';
        else $recentusers .= '<li>' . get_avatar( $username->user_email, 45 ) . '<a href="' . $username->user_url . '">' . $username->user_nicename . '</a></li>';
    }
    $recentusers .= '</ul>';
    return $recentusers;
}
add_shortcode( 'newusers', 'Bing_recently_registered_users' );

在侧边栏使用以下函数调用

1
<?php Bing_recently_registered_users(); ?>
原文链接:https://xiaohost.com/1465.html,转载请注明出处。
0

评论0

请先