任何问题请联系WX:uu16853

买模板送网站采集器 让你轻松放开双手运营网站!

购买更多有优惠!

WordPress 技巧:设置只有注册用户才能浏览特定的内容

一些网站在推广中,有时候希望提高用户的注册量,所以可能希望让有些内容是用户登陆之后才能看到的。WordPress 目前的设置中,最复杂的设置是只能把文章设置为密码保护,然后通过别的途径吧密码告诉用户才能浏览,这个方法对提高网站用户注册没有帮助,而且非常不方便。今天我就讲讲如何通过 WordPress 自定义字段完美解决这个问题。 我们增加一个自定义字段:user_only,如果这个值不为零,这这篇日志或者页面是只能给注册用户浏览,然后通过 the_content 来控制内容显示,这样就能简单的并且灵活设置具体到哪篇文章或者页面是只能注册用户浏览。详细代码如下: <?php /* Plugin Name: User only Plugin URI: http://blog.wpjam.com/m/post-for-user-only/ Description:通过给 user_only 这个自定义字段设置为 true 来设置当前文章仅限于会员浏览。 Author: Denis Version: 1.0 Author URI: http://wpjam.com */ add_filter('the_content', 'post_user_only'); function post_user_only($text){ global $post; $user_only = get_post_meta($post->ID, 'user_only', true); if($user_only){ global $user_ID; if(!$user_ID){ $redirect = get_permalink($post->ID); $text = '该内容仅限于会员浏览,请<a href="'.wp_login_url($redirect).'">登录</a>!'; } } return $text; […]

100% Secure Checkout

PayPal / MasterCard / Visa