Rob*_*Rob 2 passwords wordpress
有没有办法在Wordpress中设置受密码保护的帖子?另外,我似乎只能保护此而不是任何自定义字段.
编辑 - 尽可能避免使用插件
我假设您的意思是在前端设置受密码保护的帖子.
a)CSS:
如果您的主题使用该post_class()功能,例如:
<article <?php post_class(); ?>>...</article>
Run Code Online (Sandbox Code Playgroud)
那么它会产生:
<article class="... post-password-required ...">...</article>
Run Code Online (Sandbox Code Playgroud)
用于受密码保护的帖子.
所以你可以简单地将这些帖子作为目标:
.post-password-required {
background-color: #eee;
}
Run Code Online (Sandbox Code Playgroud)
在你的样式表中.
b)表格:
i)如果要在密码表单中添加文本,可以使用以下内容:
add_action( 'the_password_form', 'rob_the_password_form' );
function rob_the_password_form( $output )
{
$before = ' Before '; // Modify this to your needs!
$after = ' After '; // Modify this to your needs!
return $before . $output . $after;
}
Run Code Online (Sandbox Code Playgroud)
ii)如果要直接修改HTML表单,可以使用以下命令覆盖它:
add_filter( 'the_password_form', 'rob_override_the_password_form' );
function rob_override_the_password_form( $form = '' ) {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$form = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $form;
}
Run Code Online (Sandbox Code Playgroud)
这是基于食典委的例子.它使用与默认形式相同的形式.
c)标题:
要更改默认的受保护:标题前缀,您可以使用:
add_filter( 'protected_title_format', 'rob_protected_title_format' );
function rob_protected_title_format( $format )
{
$format = __( ' Members only! %s ' ); // Modify this to your needs!
return $format;
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助您设置受保护的帖子的样式.
| 归档时间: |
|
| 查看次数: |
2011 次 |
| 最近记录: |