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

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

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

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

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

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

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

    調(diào)用方法

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

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

    下面這段,是另外一個(gè)代碼,但我不知道怎么使用,懂代碼的同學(xué)請(qǐng)?jiān)谠u(píng)論區(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)益,請(qǐng)發(fā)送郵件至 1355471563#qq.com 或點(diǎn)擊右側(cè) 私信:Muze 反饋,我們將盡快處理。
    ?
    購物車
    優(yōu)惠劵
    搜索
    主站蜘蛛池模板: 伊人久久精品无码av一区| 精品无码国产一区二区三区AV| 国产一区二区电影| 国产乱码一区二区三区| 中文字幕一区日韩在线视频 | 欧美成人aaa片一区国产精品 | 视频在线观看一区二区三区| 精品亚洲AV无码一区二区| 中日av乱码一区二区三区乱码 | 亚洲国产精品无码久久一区二区 | 国产成人精品一区二区A片带套 | 一区二区三区国产精品 | 一区二区国产精品| 精品成人一区二区三区免费视频 | 国产一区二区精品尤物| 国产成人一区二区动漫精品| 国产精品美女一区二区| 国产成人一区二区动漫精品| 国产在线一区观看| 国产激情一区二区三区 | 日韩精品电影一区亚洲| 亚州国产AV一区二区三区伊在| 无码人妻精品一区二区蜜桃百度| 国产在线精品一区二区在线看| 福利一区二区三区视频午夜观看| 精品一区二区三区在线播放| 精品一区二区三区影院在线午夜 | 亚洲国产综合无码一区二区二三区| 风间由美在线亚洲一区| 日本精品高清一区二区2021| 武侠古典一区二区三区中文| 午夜精品一区二区三区在线视| 国产精品亚洲产品一区二区三区| 精品国产AⅤ一区二区三区4区| 免费无码一区二区三区蜜桃| 人妻体体内射精一区二区| 精品欧洲av无码一区二区14| 日本国产一区二区三区在线观看| 午夜一区二区在线观看| 国产精品无码不卡一区二区三区| 午夜DV内射一区二区|