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

  • A+
所属分类:Wordpress
/**
    *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' );

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

<?php Bing_recently_registered_users(); ?>

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: