<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>雨天阳光 &#187; 回复可见</title>
	<atom:link href="http://shit.name/tag/%e5%9b%9e%e5%a4%8d%e5%8f%af%e8%a7%81/feed/" rel="self" type="application/rss+xml" />
	<link>http://shit.name</link>
	<description>此人之水镜，见之莹然，若披云雾而睹青天也。</description>
	<lastBuildDate>Wed, 31 Dec 2014 06:21:04 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.33</generator>
	<item>
		<title>纯代码完美实现WordPress内容回复可见</title>
		<link>http://shit.name/pure-code-of-reply-to-read/</link>
		<comments>http://shit.name/pure-code-of-reply-to-read/#comments</comments>
		<pubDate>Thu, 24 Oct 2013 09:56:40 +0000</pubDate>
		<dc:creator><![CDATA[Oo雨天阳光oO]]></dc:creator>
				<category><![CDATA[互联二亩田]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[回复可见]]></category>
		<category><![CDATA[纯代码]]></category>

		<guid isPermaLink="false">http://shit.name/?p=289</guid>
		<description><![CDATA[前两天找到了旧博的备份数据，想着把旧文整理上来也好丰富下久不更新的博客。 整理的第一篇是智商、财商的测试类文章 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>前两天找到了旧博的备份数据，想着把旧文整理上来也好丰富下久不更新的博客。</p>
<p>整理的第一篇是智商、财商的测试类文章——<a title="【转】智商财商大测试" href="http://shit.name/iq-fq-big-test/" target="_blank">《【转】智商财商大测试》</a>，前面是题目，后面是答案。一般网页上这类的都会做分页处理，答案会放在题目的下一页，但是在一篇博文中去做分页或是另开一篇博文公布答案感觉都不合适。所以要是能像论坛那样可设置回复可见，不仅能增强与博友的互动，还能提高博客的访问量，多棒！<br />
<span id="more-289"></span><br />
网上找了一圈，有用各种各样插件达成的，其中提到最多的是“<a title="Easy2Hide" href="http://wordpress.org/plugins/easy2hide/" target="_blank">Easy2Hide</a>”，虽然它代码也蛮短的，但是“插件”二字总让我嫌弃，还是找纯代码的才能抚慰我轻微的强迫症。</p>
<p>搜索不负强迫人，总算找到一段完美的代码可以实现这个功能，具体样式请见已用该效果的博文——<a title="【转】智商财商大测试" href="http://shit.name/iq-fq-big-test/" target="_blank">《【转】智商财商大测试》</a>，我在这里介绍该代码分别对于一般主题和Mossight主题的添加方法。</p>
<p>对于一般主题，只要把这段代码添加到function.php中即可，详细代码如下：</p>
<pre class="brush: php; title: ; notranslate">
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array(&quot;notice&quot; =&gt; '

温馨提示: 此处内容需要评论本文后才能查看

'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()-&gt;ID;
if ($user_ID &gt; 0) {
$email = get_userdata($user_ID)-&gt;user_email; //对博主直接显示内容
$admin_email = &quot;on@sunny.lu&quot;; //博主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 = &quot;SELECT `comment_ID` FROM {$wpdb-&gt;comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1&quot;;
if ($wpdb-&gt;get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');
</pre>
<div class='newcode'><h2>Mossight主题</h2><div class='newcontent'><br />
Mossight主题本身就自带丰富的短代码，我们无需修改function.php，只要把这个“回复可见”添加进短代码库，在使用后台编辑器写文章时就可以很方便地调用了。（话说Mossight主题里有个下拉菜单的短代码可以暂时把想隐藏的内容藏起来，但是既点既现让懒博友又方便了，所以还是回复可见比较好）。</p>
<p>短代码库：wp-content\themes\Mossight\functions\shortcode.php<br />
找到代码</p>
<pre class="brush: php; title: ; notranslate">add_shortcode('toggle','post_toggle');</pre>
<p>另起一行插入代码：</p>
<pre class="brush: php; title: ; notranslate">
//shortcode - self
//reply_to_read
function reply_to_read($atts, $content=null) { 
extract(shortcode_atts(array(&quot;notice&quot; =&gt; '
&lt;blockquote&gt;
&lt;p style=&quot;color: #993300;&quot;&gt;&lt;strong&gt;温馨提示:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;此处内容需要评论本文后才能查看&lt;/p&gt; 
&lt;/blockquote&gt;
'), $atts)); 
$email = null; 
$user_ID = (int) wp_get_current_user()-&gt;ID; 
if ($user_ID &gt; 0) { 
$email = get_userdata($user_ID)-&gt;user_email; //对博主直接显示内容 
$admin_email = &quot;on@sunny.lu&quot;; //博主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 = &quot;SELECT `comment_ID` FROM {$wpdb-&gt;comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1&quot;; 
if ($wpdb-&gt;get_results($query)) { 
return do_shortcode($content); 
} else { 
return $notice; 
} 
} 
add_shortcode('reply', 'reply_to_read');
</pre>
<p>然后再找到最后一个QTags.addButton项</p>
<pre class="brush: php; title: ; notranslate">QTags.addButton( 'm31', '下载按钮', '【butdown href=&quot;链接&quot;】标题【/butdown】');//这用【 】防止代码运行，使用时请用[ ]替换</pre>
<p>在其后面新增一项：</p>
<pre class="brush: php; title: ; notranslate">QTags.addButton( 'm32', '回复可见', '【reply】这里输入内容【/reply】');//这用【 】防止代码运行，使用时请用[ ]替换</pre>
<p>就可以了。<br />
</div></div>
<blockquote><p>这段代码的显示样式是可以设定的，只要用Html标签和样式把“温馨提示: 此处内容需要评论本文后才能查看”美化即可,比如在Mossight主题里的，我使用了blockquote标签、p标签和css，博友们可以根据自己的需求更改。</p>
<p><span style="color: #993300;"><strong>使用方法：</strong></span><br />
一般主题：在后台编辑文章时使用“【reply】【/reply】”把要隐藏的内容包起来即可（这用【 】防止代码运行，使用时请用[ ]替换）<br />
Mossight主题：修改好shortcode.php后，进后台编辑器直接点“回复可见”按钮插入</p>
<p><strong>“回复可见”这个功能虽有优点，但也是有缺点的</strong><br />
<span style="color: #993300;"><strong>优点：</strong></span>增强与博友的互动，提高博客的访问量<br />
<span style="color: #993300;"><strong>缺点：</strong></span>回复可见不是实时的，内容要等评论审核通过后才可见</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://shit.name/pure-code-of-reply-to-read/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>
