怎么隱藏部分文章內(nèi)容,評論后可見? – wordpress開發(fā)

    實現(xiàn)隱藏WordPress部分內(nèi)容,讓用戶評論可見,如果你設(shè)置, 登陸用戶才可以評論,還可以達到用戶登陸后評論可見的效果。這一節(jié)的wordpress開發(fā)教大家如何實現(xiàn)上述功能

    通過本文章的代碼可以實現(xiàn)隱藏WordPress部分內(nèi)容,讓用戶評論可見,如果你設(shè)置, 登陸用戶才可以評論,還可以達到用戶登陸后評論可見的效果。這一節(jié)的wordpress開發(fā)教大家如何實現(xiàn)上述功能。

    怎么隱藏部分文章內(nèi)容,評論后可見? - wordpress開發(fā)
    背景圖片

    將下面的代碼添加到主題根目錄下的 functions.php 文件的<?php>下面:

    //部分內(nèi)容評論可見
    function reply_to_read($atts, $content=null) {   
            extract(shortcode_atts(array("notice" => '<p class="reply-to-read">溫馨提示: 此處內(nèi)容需要<a href="#respond" title="評論本文">評論本文</a>后才能查看.</p>'), $atts));   
            $email = null;   
            $user_ID = (int) wp_get_current_user()->ID;   
            if ($user_ID > 0) {   
                $email = get_userdata($user_ID)->user_email;   
                //對站長直接顯示內(nèi)容   
                $admin_email = "[email protected]"; //站長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 (empty($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;   
            }   
        }   
     
        add_shortcode('reply', 'reply_to_read');

    注:請自行修改第8行的郵件為管理員的。如果你的網(wǎng)站使用了ajax免刷新提交評論,你可能需要修改第2行的提示文字,提示訪客評論后刷新頁面來查看隱藏內(nèi)容。

    調(diào)用方法

    編輯文章時,使用下面的兩種簡碼調(diào)用:

    //簡碼1  任選一種使用
    
    [reply]評論可見的內(nèi)容[/reply]
    
    //簡碼2  任選一種使用
    
    [reply notice="自定義的提示信息"]評論可見的內(nèi)容[/reply]
    ?

    下面這段,是另外一個代碼,但我不知道怎么使用,懂代碼的同學(xué)請在評論區(qū)留言

    function iepress_commentonly_shortcode( $atts, $content ){
    	// set some default values
    		$display_message = __( 'You Must be Logged in and Commented to view this content,', 'iepress' );
    		$logined_message = __( 'You Must be Commented to view this content,', 'iepress' );
    		$link = wp_login_url( get_permalink() );
    		$linktext = __( 'Register or Login Here', 'iepress' );
    		$commenttext = __( 'Comment Here', 'iepress' );
    		
    		$atts = shortcode_atts(
    			array(
    				'display' => $display_message,
    				'logined'=> $logined_message,
    				'linkto' => $link,
    				'linktext' => $linktext,
    				'commenttext' =>$commenttext,
    			),
    			$atts
    		);
    		
    	if( !is_null( $content ) ) : if(!is_user_logged_in()){ 
    	$content = '' . $atts['display'] . '<a class="wpu-login-btn" href=" '. $atts['linkto'] . ' " title="'. $atts['linktext'] . '">'. $atts['linktext'] . '</a>';
    	
    	}else{ 
    	global $post;
    	 $user_id = get_current_user_ID();
    	   if( $user_id != $post->post_author && !user_can($user_id,'edit_others_posts') ){
    		$comments = get_comments( array('status' => 'approve', 'user_id' => get_current_user_ID(), 'post_id' => $post->ID, 'count' => true ) );
    		 if(!$comments) {
    			 $content = '' . $atts['logined'] . '<a class="wpu-login-btn" href=" '.get_comments_link().' " title="'. $atts['commenttext'] . '">'. $atts['commenttext'] . '</a>';
    			 }
    		}
    	}endif;
    	return '<div class="memberonly">'.$content.'</div>';
    }
    add_shortcode( 'com', 'iepress_commentonly_shortcode' );

    給TA贊賞
    共{{data.count}}人
    人已贊賞
    ??
    Npcink上的部份代碼及教程來源于互聯(lián)網(wǎng),僅供網(wǎng)友學(xué)習(xí)交流,若您喜歡本文可附上原文鏈接隨意轉(zhuǎn)載。
    無意侵害您的權(quán)益,請發(fā)送郵件至 1355471563#qq.com 或點擊右側(cè) 私信:Muze 反饋,我們將盡快處理。
    ?
    購物車
    優(yōu)惠劵
    搜索
    主站蜘蛛池模板: 在线精品动漫一区二区无广告| 丰满岳妇乱一区二区三区| 亚洲国产一区二区视频网站| 夜夜添无码试看一区二区三区| 欧洲精品码一区二区三区免费看 | 欧洲精品一区二区三区在线观看| 免费在线观看一区| 国产精品va一区二区三区| 在线观看一区二区三区av| 久久综合九九亚洲一区| 亚洲视频一区二区三区四区| 国产精品亚洲高清一区二区| 亚洲av成人一区二区三区在线播放| 中文字幕无码一区二区免费| 一区二区三区在线播放| 国产一区二区三区免费在线观看| 亚洲国产激情在线一区| 日韩人妻一区二区三区蜜桃视频 | 无码精品蜜桃一区二区三区WW| 国产对白精品刺激一区二区 | 色一乱一伦一区一直爽| 天海翼一区二区三区高清视频 | 国产波霸爆乳一区二区| 中文字幕一区二区三区精华液 | 国产精品香蕉在线一区| 国产高清在线精品一区| 久久毛片一区二区| 亚洲高清一区二区三区电影 | 一区二区三区视频网站| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲AV无码一区二三区| 一区二区三区免费视频观看| 国产免费一区二区三区免费视频 | 国产成人精品日本亚洲专一区| 香蕉久久一区二区不卡无毒影院| 精品国产亚洲一区二区在线观看 | а天堂中文最新一区二区三区| 日韩精品一区二区三区视频| 国产成人精品a视频一区| 国产无线乱码一区二三区| 亚洲福利一区二区三区|