Wednesday, December 7, 2011

Membuat Recent Comment Dengan Menggunakan Javascript

recent comment

Recent comment membantu anda terutama sebagai admin untuk melihat komentar terbaru yang masuk kedalam blog anda, sehingga anda bisa sewaktu itu juga membalas komentar dari pengunjung. Ini sangat penting, terutama bagi blog yang mempunyai banyak sekali artikel postingan. Meskipun kita juga bisa melihatnya secara langsung komentar yang masuk tersebut melalui tab comment di dashboard blogger. untuk posting kali ini kita akan membuat recent comment pada bloganda dengan menggunakan javascript. 









Silahkan anda copy kode berikut ini dan letakkan setelah kode <body>  pada template anda 

<script style='text/javascript'>function showrecentcomments(json) {for (var i = 0; i &lt; 6; i++) {var entry = json.feed.entry[i];var ctlink;if (i == json.feed.entry.length) break;for (var k = 0; k &lt; entry.link.length; k++) {if (entry.link[k].rel == &#39;alternate&#39;) {ctlink = entry.link[k].href;break;}}ctlink = ctlink.replace(&quot;#&quot;, &quot;#comment-&quot;);var ptlink = ctlink.split(&quot;#&quot;);ptlink = ptlink[0];var txtlink = ptlink.split(&quot;/&quot;);txtlink = txtlink[5];txtlink = txtlink.split(&quot;.html&quot;);txtlink = txtlink[0];var pttitle = txtlink.replace(/-/g,&quot; &quot;);pttitle = pttitle.link(ptlink);if (&quot;content&quot; in entry) {var comment = entry.content.$t;}elseif (&quot;summary&quot; in entry) {var comment = entry.summary.$t;}else var comment = &quot;&quot;;var re = /&lt;S[^&gt;]*&gt;&gt;/g;comment = comment.replace(re, &quot;&quot;);if (i==0) {document.write(&#39;&lt;li class=&quot;clear&quot; style=&quot;border-top: 0pt none;&quot;&gt;&#39;);}else{document.write(&#39;&lt;li class=&quot;clear&quot;&gt;&#39;);}document.write(&#39;&lt;a href=&quot;&#39; + ctlink + &#39;&quot;&gt;&lt;strong&gt;&#39; + entry.author[0].name.$t + &#39;&lt;/strong&gt;&lt;/a&gt; says:&#39;);if (comment.length &lt; 100) {document.write(&#39;&lt;a target=&quot;_blank&quot; href=&quot;&#39; + ctlink + &#39;&quot;&gt;&#39;+comment+ &#39;&lt;/a&gt;&#39;);}else{comment = comment.substring(0, 100);var quoteEnd = comment.lastIndexOf(&quot; &quot;);comment = comment.substring(0, quoteEnd);document.write(&#39;&lt;a target=&quot;_blank&quot; href=&quot;&#39; + ctlink + &#39;&quot;&gt;&#39;+comment + &#39;...&lt;/a&gt;&#39;);}}document.write(&#39;&lt;/li&gt;&#39;);}</script>
Kemudian anda tambahkan element baru html/javascript dan berikan titlerecent comment atau apa saja terserah anda, lalu masukkan kode berikut ini 
<ul id='recentcomments'>
<script src='/feeds/comments/default?alt=json-in-script&amp;callback=showrecentcomments'/>
</ul></script></ul>

Selamat mencoba. Semoga berhasil.

No comments:

Post a Comment

My Ping in TotalPing.com
Feedage Grade D rated
Preview on Feedage: web-design Add to My Yahoo! Add to Google! Add to AOL! Add to MSN
Subscribe in NewsGator Online Add to Netvibes Subscribe in Pakeflakes Subscribe in Bloglines Add to Alesti RSS Reader
Add to Feedage.com Groups Add to Windows Live iPing-it Add to Feedage RSS Alerts Add To Fwicki
Ping your blog, website, or RSS feed for Free