Wordpress 密码保护存档和自定义帖子类型的单个帖子

chr*_*ian 4 wordpress password-protection custom-post-type

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

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

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

谢谢,

小智 6

我发现快速密码保护存档的唯一方法是创建一个模板来检索自定义帖子类型数据并将其与可以密码保护的页面相关联。 http://codex.wordpress.org/Page_Templates

一旦该页面受密码保护,您就会找到帖子 ID 以将其应用到单个 {your_custom_post_type}.php 中,如下所示:

<?php
if ( !post_password_required('{protected_post_id}') ) : ?>

//protected content here

<?php else:
    //show the password form of the protected page
    echo get_the_password_form('{protected_post_id}');                 

endif; ?>
Run Code Online (Sandbox Code Playgroud)

这使您不必对自定义帖子类型下的每个帖子进行密码保护。