<?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>phoenixheart - portfolio &#38; more &#187; wordpress hack</title> <atom:link href="http://www.phoenixheart.net/tag/wordpress-hack/feed/" rel="self" type="application/rss+xml" /><link>http://www.phoenixheart.net</link> <description>phoenixheart - portfolio &#38; more</description> <lastBuildDate>Wed, 25 Aug 2010 03:02:03 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <script type="text/javascript">/*<![CDATA[*/if(typeof Meebo=="undefined"){Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};(function(q){var args=arguments;if(!document.body){return setTimeout(function(){args.callee.apply(this,args)},100);}var d=document,b=d.body,m=b.insertBefore(d.createElement('div'),b.firstChild);s=d.createElement('script');m.id='meebo';m.style.display='none';m.innerHTML='<iframe id="meebo-iframe"></iframe>';s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;b.insertBefore(s,b.firstChild);})({network:'phoenixheartnet_bo16we'});}/*]]>*/</script> <item><title>WordPress: Thank that first time commentator!</title><link>http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/</link> <comments>http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/#comments</comments> <pubDate>Sat, 07 Nov 2009 05:12:08 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Blahblahblah]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[Server stuffs]]></category> <category><![CDATA[user interaction]]></category> <category><![CDATA[wordpress]]></category> <category><![CDATA[wordpress hack]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=392</guid> <description><![CDATA[Thumbnail credit: Premshree Pillai To a website, comments are important &#8211; this you must agree. But not all visitors leave comments &#8211; in fact, very, very few. Most of them care about the content only, and tend to leave (bounce) the site right after getting the information they need (so sad a life, huh?) Many [...]]]></description> <content:encoded><![CDATA[<p><small>Thumbnail credit: <a
href="http://www.flickr.com/photos/premshree/">Premshree Pillai</a></small></p><p><span
class="drop-cap">T</span>o a website, comments are important &#8211; this you must agree. But not all visitors leave comments &#8211; in fact, very, very few. Most of them care about the content only, and tend to leave (bounce) the site right after getting the information they need (so sad a life, huh?)</p><p>Many tips have been introduced and used to encourage visitors to contribute to your site via comments. To my knowledge, and to name a few:</p><ul><li>Use dofollow links in comments. By default, WordPress and other blogging systems mark links in comments with <code>rel="nofollow"</code> attribute. This attribute tells search engines to not follow the links, which means the commenter&#8217;s site will not be able to share any Google juice with you. While effective in fighting spammers, this technique may a bit disappoint the real visitors. Plugins like <a
href="http://wordpress.org/extend/plugins/sem-dofollow/">Dofollow</a> address this problem and remove &#8220;nofollow&#8221; attribute from comment links.</li><li>Further promote the commenter&#8217;s blog (if any). <a
href="http://wordpress.org/extend/plugins/commentluv/">CommentLuv</a> is a plugin that &#8220;will visit the site of the comment author while they type their comment and retrieve a selection of their last blog posts, tweets or digg submissions which they can choose one from to include at the bottom of their comment when they click submit&#8221;.</li><li>Choose a (random) comment to give small prizes such as free ebooks, preminum themes etc.</li><li>Explicitly ask the readers to give comments at the end of the article &#8211; &#8220;Please share your thoughts&#8221;, &#8220;What do you think?&#8221;, &#8220;What say you?&#8221; etc. etc.</li></ul><p>Today I would like to mention another method to encourage commenting. Though this won&#8217;t likely attract more commenters, it may encourage existing ones to leave more comments and become more effective contributors.</p><p>The method is called &#8220;Thank first time commenters&#8221; and it works like this: <span
id="more-392"></span></p><p>Normally when a visitor leaves a comment for the first time on your blog, the comment is displayed under &#8220;awaiting moderation&#8221; status and visible to him only. When there&#8217;s nothing wrong with this approach, it&#8217;s not really interesting for the commenter himself. Now how about showing him a &#8220;thank you&#8221; or &#8220;welcome&#8221; message, or better, a whole page, for the first time contributing his [great] ideas to your site? This time it&#8217;s much cooler!</p><p>Let&#8217;s turn the idea into real action for a WordPress site.</p><h3>Step 1. Detect first time commenter</h3><p><img
class="shot" src="/wp-content/uploads/2009/11/comments.gif" alt="Comments" width="470" height="136" /><br
/> <small>Original image from <a
href="http://www.flickr.com/photos/chrismar/">Chrismar</a></small></p><p>To detect whether the comment author is leaving his first comment on you site, we need to <em>hook</em> into one of the comment-related functions (you can read about hooks <a
href="http://codex.wordpress.org/Plugin_API">here</a>). For this purpose I use <strike><code>comment_post()</code>, but there may be some other alternatives which I don&#8217;t know about</strike> <code>comment_post_redirect</code> filter. This filter is applied just before WordPress redirects the commentator after him posting a comment &#8211; exactly what we need.</p><p>In the theme&#8217;s <code>functions.php</code> page, add these lines:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_post_redirect'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'check_first_time_comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * This functions accepts one parameter being the location to redirect commentators to
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> check_first_time_comment<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// get the comment from global variables</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// if it's not &quot;unapproved&quot;, don't modify the redirect location</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_approved</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$location</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// now check if it's really the first time the commenter comments</span>
    <span style="color: #666666; font-style: italic;">// to do this, we check the number of comments this author have left on our site</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT COUNT(comment_ID) from <span style="color: #006699; font-weight: bold;">{$wpdb-&gt;prefix}</span>comments WHERE comment_author_email='<span style="color: #006699; font-weight: bold;">{$comment-&gt;comment_author_email}</span>'&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$location</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// he's left more than 1 comment - do nothing with him</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//--- if we reach here, this is the first comment he leaves on our site. Do our stuffs now! ---//</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// first save the comment data into session. We'll use it later</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">session_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_time_comment'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// now modify the $location so that WordPress redirects this commentator to our special page</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'/thank-you-for-contribution/'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>What the code does is pretty self-descriptive. The function <code>check_first_time_comment($location)</code> is triggered just before WordPress redirects the commentator to a location (being the post, the page, or the error page). It takes one parameter, being the location url. Upon triggered, it checks for the status of the comment and only does its deeds if the comment is &#8220;unapproved&#8221; (status code 0). Then, it does a further check to see if this is really the first time the comment author leaves a comment on the site with the email address. If this is true, it saves the comment data into session for later retrieval, and modifies the location string to redirect the commenter to the thank you page.</p><h3>Step 2. Create a &#8220;Thank you&#8221; landing page</h3><p><img
class="shot" src="/wp-content/uploads/2009/11/thanks-narrow.jpg" alt="Thank you!" width="470" height="130" /><br
/> <small>Original image by <a
href="http://www.flickr.com/photos/premshree/">Premshree Pillai</a></small></p><p>This is the page where our valuable commenter is redirected to. To create such a page, first copy page.php in the theme folder into thank-you-page.php. Open it and locate these lines on the top:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name: Page
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>Change the template name to something descriptive like &#8220;Thank You Page&#8221;, and add some logic, like this:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name: Thank You Page
*/</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">session_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">session_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_time_comment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// the page should not be directly accessed</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: /'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// now get the comment data from session and utilize it</span>
<span style="color: #000088;">$first_time_comment</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_time_comment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// clear the session</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'first_time_comment'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$the_post</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_time_comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_post_ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// get the post of the comment</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$the_post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// for some reason, we cannot find the post.</span>
    <span style="color: #666666; font-style: italic;">// The action here depends on you. For me I redirect to home.</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: /'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// tell the browser not to cache this page in anyway</span>
<span style="color: #666666; font-style: italic;">// !IMPORTANT: You may also want to exclude this page from cache plugins too!</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: no-cache, must-revalidate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
&quot;Thank you&quot; content goes here
With the post on hand, you can enrich this thank you page with:
- similar posts
- posts in the same categories
- random posts
- most read posts
- most commented posts etc.
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>Save the template. Now go to WordPress control panel, create a new page with &#8220;Thank You Page&#8221; as the template, and <code>thank-you-for-contribution</code> as the slug. You may want to disable ping and comments for the page too.</p><p>There! Your blog is now ready to welcome the first time commentators!</p><p>But wait&#8230; there&#8217;s still a catch.</p><h3>Step 3. Post-production</h3><p>Now, if you list down your pages somewhere on your blog, &#8220;Thank You&#8221; page will stupidly appear. The fix is easy: <a
href="http://codex.wordpress.org/Template_Tags/wp_list_pages">exclude the page ID</a>. Also, if you have a cache plugin installed, it&#8217;s best to exclude Thank You page from caching.</p><p>Want to see it in action? Just leave a comment here as a new commentator!</p> <img
style='display:none' id="post-392-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/',title:'WordPress: Thank that first time commentator!',tweet:'Thumbnail credit: Premshree Pillai To a website, comments are important &#8211; this you must agree.',description:'Thumbnail credit: Premshree Pillai To a website, comments are important &#8211; this you must agree.'})"><script type='text/javascript'>document.getElementById("post-392-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching using disk

Served from: www.phoenixheart.net @ 2010-09-08 08:55:55 -->