Url 到 id:16: /?cat=16
作者:
显示文章的作者
显示文章作者的描述
显示文章作者的登录名
显示文章作者的firstname(名)
显示文章作者的lastname(姓)
显示文章作者的昵称
显示文章作者的ID号
显示文章作者的电子邮箱
显示文章作者的网站地址
显示一个以文章作者名为链接名
(不推荐使用) 显示文章作者的icq
显示文章作者的aim
显示文章作者的yim
(不推荐使用) 显示文章作者的msn
显示文章作者已发表文章的篇数
显示文章作者已发表文章列表的链接
(不推荐使用) 显示blog所有作者相关信息
WordPress前台显示当前登录用户注册时间
将代码添加到当前主题functions.php中:
function user_registered_date(){
$userinfo=get_userdata(get_current_user_id());
$authorID= $userinfo->id;
$user = get_userdata( $authorID );
$registered = $user->user_registered;
echo ‘注册时间’ . date( ‘Y年m月d日’, strtotime( $registered ) );
}
$userinfo=get_userdata(get_current_user_id());
$authorID= $userinfo->id;
$user = get_userdata( $authorID );
$registered = $user->user_registered;
echo ‘注册时间’ . date( ‘Y年m月d日’, strtotime( $registered ) );
}
在前端模板使用以下的代码调用显示:
<?php if ( is_user_logged_in() ) { user_registered_date();} ?>
只有登录用户可见。
WordPress前台显示当前登录用户最后登录时间
将下面的代码添加到当前主题functions.php中:
// 记录登录时间
function user_last_login($user_login) {
global $user_ID;
// 纠正8小时时差
date_default_timezone_set(PRC);
$user = get_user_by( ‘login’, $user_login );
update_user_meta($user->ID, ‘last_login’, date(‘Y-m-d H:i:s’));
}
add_action(‘wp_login’,’user_last_login’);
// 调用最后登录时间
function get_last_login($user_id) {
$last_login = get_user_meta($user_id, ‘last_login’, true);
$date_format = get_option(‘date_format’) . ‘ ‘ . get_option(‘time_format’);
$the_last_login = mysql2date($date_format, $last_login, false);
echo $the_last_login;
}
function user_last_login($user_login) {
global $user_ID;
// 纠正8小时时差
date_default_timezone_set(PRC);
$user = get_user_by( ‘login’, $user_login );
update_user_meta($user->ID, ‘last_login’, date(‘Y-m-d H:i:s’));
}
add_action(‘wp_login’,’user_last_login’);
// 调用最后登录时间
function get_last_login($user_id) {
$last_login = get_user_meta($user_id, ‘last_login’, true);
$date_format = get_option(‘date_format’) . ‘ ‘ . get_option(‘time_format’);
$the_last_login = mysql2date($date_format, $last_login, false);
echo $the_last_login;
}
在主题模板适当位置添加调用代码:
<?php global $userdata; get_currentuserinfo(); get_last_login($userdata->ID); ?>
如果想在后台用户列表中显示最后登录时间可以安装插件:WP Last Login 。
WordPress前台显示登录用户角色
将下面的代码添加到当前主题functions.php中:
function get_user_role() {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
return $user_role;
}
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
return $user_role;
}
在主题模板适当位置添加调用代码:
<?php echo get_user_role(); ?>
调用用户其它信息,可以使用下面的WordPress用户信息函数:
<?php
global $current_user;
get_currentuserinfo();
echo ‘用户名: ‘ . $current_user->user_login . “\n”;
echo ‘用户邮箱: ‘ . $current_user->user_email . “\n”;
echo ‘名字: ‘ . $current_user->user_firstname . “\n”;
echo ‘姓氏: ‘ . $current_user->user_lastname . “\n”;
echo ‘公开显示名: ‘ . $current_user->display_name . “\n”;
echo ‘用户 ID:’ . $current_user->ID . “\n”;
?>
global $current_user;
get_currentuserinfo();
echo ‘用户名: ‘ . $current_user->user_login . “\n”;
echo ‘用户邮箱: ‘ . $current_user->user_email . “\n”;
echo ‘名字: ‘ . $current_user->user_firstname . “\n”;
echo ‘姓氏: ‘ . $current_user->user_lastname . “\n”;
echo ‘公开显示名: ‘ . $current_user->display_name . “\n”;
echo ‘用户 ID:’ . $current_user->ID . “\n”;
?>