A-A+

wordpress文章密码保护提示

2015年01月05日 PHP开源系统 暂无评论 阅读 0 views 次

在发布文章的时候,wordpress是可以选择文章是否进行密码保护的,如果进行密码保护则在查看文章的时候会有这样的显示“这篇文章是受保护的文章,请输入密码继续阅读”,如果不能输入正确的密码则不能查看。

有一些文学或者下载之类的站点需要提供这样的功能,指定的文章只给会员或者VIP查看就可以使用这样的功能了,实例代码如下:

[code lang="php"]
function xiariboke_password_hint( $c ){
global $post, $user_ID, $user_identity;
if ( empty($post->post_password) )
return $c;
if ( isset($_COOKIE['wp-postpass_'.COOKIEHASH]) && stripslashe
s($_COOKIE['wp-postpass_'.COOKIEHASH]) == $post->post_password )
return $c;
if($hint = get_post_meta($post->ID, 'password_hint', true)){
$url = get_option('siteurl').'/wp-pass.php';
if($hint)
$hint = '密码提示:'.$hint;
else
$hint = "请输入您的密码";
if($user_ID)
$hint .= sprintf('欢迎进入,您的密码是:', $user_identity, $po
st->post_password);
$out = <<

这篇文章是受保护的文章,请输入密码继续阅读:


END;
return $out;
}else{
return $c;
}
}
add_filter('the_content', 'xiariboke_password_hint');
[/code]

将此代码加入到主题文件 functions.php 里即可,前台看一下你的文章是否已经被密码保护起来了呢~~

标签:

给我留言