单圈内部while循环。php您可以这样放置条件
if(in_category(\'Catetory_slug\')){ //Specifying category whom we don\'t want to see by no logged in users
if(is_user_logged_in()){ //Checking if user logged in or not
//code inside single.php
}else{
Echo "You need to login to view this post."; //message for no logged in users
}}
这可以为其他主题文件模板完成,就像我们为single所做的一样。php。
UPDATE
如果你想让一个用户看不到另一个用户的帖子,那么你可以使用这两个函数来实现这一点
- get_the_author(): 获取帖子作者的显示名称wp_get_current_user(): 要获取登录用户的信息,请使用以下while循环
//storing autor\'s display name in variable
$post_author = get_the_author();
$current_user = wp_get_current_user();
//storing autor\'s display name in variable
$current_user_info = $current_user->display_name;
//Chacking if bot strings (display names) are equal or not
if (strcmp($post_author, $current_user_info) == 0) {
//Your Code to display post\'s content
}
您还可以将if条件放在ID上,而不是显示名称上。为此,您需要对上述代码进行2次更改更换get_the_author() 具有的函数get_the_author_meta()
- 并替换以下代码行
$current\\u user\\u info=$current\\u user->display\\u name;
使用此
$current_user_info = $current_user->ID;
要了解更多信息,请在我的链接中详细阅读此函数。