简体   繁体   English

如何在WordPress中制作自定义模板作为受密码保护的页面?

[英]How to make a custom template in WordPress work as a password protected page?

I'm building a page with a custom template. 我正在构建一个包含自定义模板的页面。

The thing is, I need this page to be password protected, or at least accessible to logged in users, but even if I set it as such (Private/Password protected) in the New Pages section in WordPress Administration, it won't display the menu entry nor the content (if Private) or it would show the page contents immediately (if Password protected). 问题是,我需要这个页面受密码保护,或至少可以登录用户访问,但即使我在WordPress管理的新页面部分中设置它(私人/密码保护),它也不会显示菜单条目或内容(如果是私人)或它将立即显示页面内容(如果密码保护)。

I've read somewhere that the_content() function is what makes this work, but as you can guess, my custom template doesn't use the_content() at all, and it's all based on custom content. 我已经读过某个地方,the_content()函数是使这个工作的原因,但正如你猜测的那样,我的自定义模板根本不使用the_content(),而是全部基于自定义内容。

Do you happen to know how can I (re)implement these two options? 你碰巧知道我怎样才能(重新)实现这两个选项?

There's a much more elegant and reliable approach to checking if a post is private; 有一种更加优雅和可靠的方法来检查帖子是否是私密的;

if ( post_password_required() ) {
    // It's protected and they haven't entered a password, so ask for one:
    the_content();

} else {
    // It's not protected or they have entered a password
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM