Jan02
5
Share

N 个 WordPress 小技巧(四)

多灾多难又充满美好记忆的2008年已经过去了,在你的博客里是否有很多引起读者共鸣的文章?是否想让更多的新读者参与这些热门话题的讨论当中?好吧,让三两饭告诉你该如何引用过去一年中评论最多的十篇文章,看看我的解决方法:

在你的侧栏或者其它想要引用此功能的位置,加入如下代码:

<h2>Most commented posts from 2008</h2>
<ul>
<?php
$result = $wpdb->get_results("SELECT comment_count,ID,post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN '2008-01-01' AND '2008-12-31' ORDER BY comment_count DESC LIMIT 0 , 10");
 
foreach ($result as $topten) {
    
$postid = $topten->ID;
    
$title = $topten->post_title;
    
$commentcount = $topten->comment_count;
    
if ($commentcount != 0) {
    
?>
         <li><a href="
<?php echo get_permalink($postid); ?>"><?php echo $title ?></a></li>
    
<?php }
}
?>
</ul>

OK ,就这样了,在新年开始的时候,展示一下2008年讨论最多、留言最多的文章,怀旧一把。

Filed under: | Tagged:

5 Responses to “N 个 WordPress 小技巧(四)”

  1. 醉倚西风 January 03,2009 10:08 AM#

    学习拉拉 哈哈

    回复

  2. 雅丹地貌博客 January 02,2009 01:31 PM#

    学习了 新年快乐!

    回复

  3. NetPuter January 02,2009 10:07 AM#

    如果是我,喜欢写成一段 function 在主题目录的 function.php 中,方便调用~
    有可能的,建议缓存一下.因为2008年已经过去,数据不会变动.

    回复

    三两饭 在 January 3rd, 2009 8:14 pm 回复:

    这个建议很好

    回复

  4. 火星人 January 02,2009 08:52 AM#

    沙发~~~

    回复

Leave a Reply