WordPress的-通过登录保护页面 [英] Wordpress - Protect page by login
问题描述
我有一个网站,我将创建一个简单的仅限会员"页面. 我会为页面内容添加保护,以便只有编辑者和管理员可以访问.
I've a site and I would create a simply "Members only" page. I would add a protection to a page content so only editors and administrators can access.
该页面对所有用户都应该可见,但是当访客单击它时,页面内容受用户名/密码保护.当用户填写这些字段时,页面会自动重定向以保护内容.
This page should be visible to all users, but when a guest click on it, the page content is protected by username/password. When user fill these fields, the page automatically redirect to protect content.
有没有我可以考虑的插件或方法?
Is there a plugin, or method, that I can consider?
推荐答案
探究地,有一些用于这类东西的插件,我主要是构建自己的主题并在其中实现.
There probely is some plugin for this kind of stuff, i mostly build my own themes, and implement it there.
如果您只想保护一个页面,则可以为该页面创建一个自己的模板文件. 如果页面名称是"secrets",则可以在teames文件夹中将page.php(或index.php)复制到page-secrets.php,并添加一些php代码来保护该页面.
if its just one page you want to protect, you could make a own template file for that page. if the page name is "secrets", you could in the teames folder copy the page.php (or index.php) to page-secrets.php, and add some php code to protect that page.
一个相对简单的版本可能是:
a relly simple version could be:
<?php
get_header();
if($_POST['password'] == 'the password')
{
...
}
else
{
echo "<h2>This page is password protected</h2>";
echo "<form action='?' method='post'>";
echo "<label><span>Password</span>";
echo "<input type='password' name='password' /></label>";
echo "<input type='submit' name='Authenticate' />";
echo "</form>";
}
get_footer();
?>
其中...是在get_header()之间从page.php(或index.php)复制的内容;和get_footer();行
where ... is the copied content from page.php (or index.php) between the get_header(); and get_footer(); rows
这篇关于WordPress的-通过登录保护页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!