我能找到的大多数代码都是关于根据登录用户的角色向其显示的特定内容。
我想做相反的事。
这基本上就是我想做的:
如果作者有"订阅者"角色,则显示一些html A.如果作者是"客户"角色,显示html B.
我认为这应该是可能的,但我不确定从哪里开始。
这是我正在使用但不起作用的片段,所以可能在某个地方出错?
<?php $current_author_roles = get_the_author_meta('roles');?>
<?php if ( in_array('Customer', $current_author_roles) ) { ?>
//do something
<?php } else { ?>
//do something else
<?php } ?>
使用条件。例如:
$current_author_roles = get_the_author_meta('roles');
if ( in_array('Customer', $current_author_roles) ) {
// do something
}
您可以在Codex中阅读更多关于get_the_author_meta()的信息。