有没有一种简单的方法来密码保护自定义帖子类型的存档和单个帖子?

我找到了这篇关于密码保护单个帖子的文章,但仍然在存档循环中丢失了。我希望它只显示密码框,直到用户登录。

https://wordpress.stackexchange.com/questions/4952/forcing-all-posts-associated-with-a-custom-post-type-to-be-private

谢谢,

最佳答案

对于单个页面,您只需编辑 single.php 并添加以下内容:

<?php

if ( is_user_logged_in() ) {
  // Show Post to Logged in User
}
else {
  //Show password field
}

?>

如果像您提到的那样,您使用的是自定义帖子类型或存档模板,则可以将与上述相同的方法应用于 single-[custom-post-type-name].phparchive.php

关于Wordpress 密码保护存档和自定义帖子类型的单个帖子,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12822923/

10-11 20:17
查看更多