WordPress有些時(shí)間我們需要一些特色功能,下面我來介紹WordPress設(shè)置只有注冊(cè)用戶才能瀏覽特定的內(nèi)容,有需要的朋友可學(xué)習(xí)學(xué)習(xí).
我們?cè)黾右粋€(gè)自定義字段:user_only,如果這個(gè)值不為零,這這篇日志或者頁面是只能給注冊(cè)用戶瀏覽,然后通過 the_content 來控制內(nèi)容顯示,這樣就能簡(jiǎn)單的并且靈活設(shè)置具體到哪篇文章或者頁面是只能注冊(cè)用戶瀏覽,詳細(xì)代碼如下:
- <?php
- 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 = '該內(nèi)容僅限于會(huì)員瀏覽,請(qǐng)<a href="'.wp_login_url($redirect).'">登錄</a>!';//開源軟件:Vevb.com
- }
- }
- return $text;
- }
- ?>
把上面帶復(fù)制成一個(gè)文件上傳到插件目錄,激活即可.
新聞熱點(diǎn)
疑難解答
圖片精選