最新公告
  • 资源宝-专注于优秀资源,本站秉承服务宗旨 履行“站长”责任, 服务永无止境!
  • WordPress实现文章部分内容评论/回复后可见的功能

    已弃用QQ,邮箱:[email protected] 【哔哩哔哩留言】上线看见信息第一时间回复,本站大部分源码亲测

    之前分享过一篇文章,是关于WordPress如何实现部分文章内容需要登录后才能查看,今天给大家带来一篇WordPress实现文章内容评论/回复后可见的功能。
    这个功能实现起来很容易,而且可以提高用户积极性,是一个非常不错的功能。
    下面放出核心代码

    //WordPress实现文章部分内容评论后可见
    function reply_to_read($atts, $content=null) {
    	extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" rel="external nofollow"  rel="external nofollow"  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;
    		//对博主直接显示内容
    		$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');
    

    使用方法

    1、 首先将以下代码添加到主题的functions.php文件里。
    2、然后在编辑文章时添加下面两种方式的其中一种即可隐藏文章部分内容。

    温馨提示: 此处内容需要评论本文后才能查看.
    回复后才显示哟
    
    资源宝-—专注于优秀资源搜集共享与发布
    资源宝 » WordPress实现文章部分内容评论/回复后可见的功能
    本站所有资源来源于网络,仅限用于学习研究;无任何技术支持!不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除内容。如果您喜欢,请支持正版。如有侵权请邮件与我们联系处理。

     本站部分源码亲测,单个源码赞助前请咨询 

    • 99999访问总数
    • 206会员总数(位)
    • 9539资源总数(个)
    • 900 资源大小(GB)
    • 2376稳定运行(天)

    提供最优质的资源集合

    网站源码 APP源码