Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示WP作者和未登录用户的PHP代码_Php_Wordpress_Plugins_Badge - Fatal编程技术网

显示WP作者和未登录用户的PHP代码

显示WP作者和未登录用户的PHP代码,php,wordpress,plugins,badge,Php,Wordpress,Plugins,Badge,我一直在修改一个长期废弃的插件项目,该项目为Wordpress提供了一个Stackoverflow风格的徽章系统。我已经升级了它的代码,这样它就可以在新的Wordpress版本中运行了 如果感兴趣,您可以在此处查看整个代码: 我想在author.php页面中添加一个代码,列出作者获得的徽章。到目前为止,我仅使用以下工作代码显示登录用户的徽章: <?php $user_id = get_current_user_id(); if ($user_id != 0) { rhb_list_ba

我一直在修改一个长期废弃的插件项目,该项目为Wordpress提供了一个Stackoverflow风格的徽章系统。我已经升级了它的代码,这样它就可以在新的Wordpress版本中运行了

如果感兴趣,您可以在此处查看整个代码:

我想在author.php页面中添加一个代码,列出作者获得的徽章。到目前为止,我仅使用以下工作代码显示登录用户的徽章:

<?php
$user_id = get_current_user_id();
if ($user_id != 0) {
  rhb_list_badges(array('user_ID' => $user_id));
}
?>

我被告知使用此代码显示作者的徽章:

<?php
$author = get_user_by( 'slug', get_query_var( 'author_name' ) ); 
if ($author->ID > 0) {
  rhb_list_badges(array('user_ID' => $author->ID));
}
?>


但它不会在页面上返回任何内容。为什么?我做错了什么?如何更改工作的get_current_user_id代码示例,使其显示作者的徽章,而不是登录用户的徽章?

您可以在author.php页面上循环之前使用此代码

<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
rhb_list_badges(array('user_ID'=>$curauth->ID));
?>


摘自。

我刚刚尝试了一下这段代码,它似乎也在循环中工作。太好了,很高兴这对您有用。如果遇到问题,codex页面还有其他示例。