关于WordPress提高用户互动的功能还是比较多的,比如我们需要输入密码访问隐藏内容,需要特定的权限会员才可以访问查看。以及我们看到隐藏内容回复可见,这个又找到案例可以试试记录下来。

//文章内容回复可见  
add_shortcode('reply', 'reply_to_read');

function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '

温馨提示:此处内容需要评论本文后才能查看。

'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "admin@itbulu.com"; //博主Email
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (emptyempty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_post_ID={$post_id} and comment_approved='1' and comment_author_email='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}

代码部分添加到功能页面,修改下里面的邮箱。
然后我们需要在合适的部分隐藏:
[reply]需要隐藏的内容[/reply]    

对于短代码,我们也可以通过"强化WordPress默认编辑器小工具按钮的办法(自定义快速工具栏)"效仿添加。
关于WP隐藏内容扩展阅读:
1、简单代码实现WordPress隐藏内容用密码才可显示
2、WordPress精简代码之删除/隐藏WordPress版本号方法
3、WordPress关注微信公众号获取验证码查看隐藏内容


扫描二维码,在手机上阅读!