记录生活 学习SEO优化 | 他日若遂凌云志 敢笑黄巢不丈夫
>>Home > 学习笔记 > 制作和海天博客一样的排行榜

制作和海天博客一样的排行榜

Tags: | | 作者:海天无影

虽然开博以来,海天的博客才出现了两位风云人物,但是海天的排行榜还是在每个月更新着,就算哪一个月忘了,经过随缘同学的提醒也会立即补上的。看到有朋友需要海天博客的排行榜调用代码,正好今天没东西写,嘿嘿就写下吧。

其实这个代码不是海天原创,因为网上的wordpress类似的代码很多,海天也只是放在一个页面里,就成了海天博客的排行榜了。

其实这段生成代码,是参照的万戈同学的代码。代码只调用当月的排行榜,然后海天再将上个月的排行榜截图下来,发表上去就OK了。

排行榜的调用代码,只需要将下列代码放入functions.php文件中

$identity="comment_author";
$passwordpost = " AND post_password=''";
$userexclude = " AND comment_author != '海天无影'"; //这个是去掉名为海天无影的用户头像
$approved = " AND comment_approved='1'";
$shownumber = 24;
$counts = $wpdb->get_results("SELECT COUNT(" . $identity . ") AS cnt, comment_author, comment_author_url,comment_author_email FROM (SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE MONTH(comment_date)=MONTH(now()) and YEAR(comment_date)=YEAR(now())" .
$userexclude . $passwordpost . $approved . ") AS tempcmt GROUP BY " . $identity . " ORDER BY cnt DESC LIMIT " . $shownumber);

//real number of comments
function no_admin_number($no='', $one='', $twomore='') {
global $wpdb, $tablecomments, $post;
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_type = '' AND comment_approved = '1' AND comment_author != '海天无影'");
$cnt = count($comments);
if (!$cnt)
echo $no;
elseif ($cnt == 1)
echo $one;
else
echo str_replace("%", $cnt, $twomore);
}

如果某个月你忘记截取图片了,只需要将其中的红色代码改为那个月份的数字,排行榜生成的就是那个月的排行了。

下面是制作排行榜页面了,新建文件listpage.php然后将下列代码复制进去,上传到根目录。

<?php
/*
Template Name: List Page Template PAGE
*/
?>
<?php get_header(); ?>
<div class="w970">
<div id="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<p>排行的描述,你自己写吧,呵呵~</p>
<br />
<div class="listwall">
<ul class="ffox_most_active">
<?php if ( $counts ) : foreach ($counts as $count) :
echo '<li>' . '<div class="ffox_most_active_img"><a href="'. $count->comment_author_url . '" target="_blank" title="' . $count->comment_author . ' ('. $count->cnt . '层楼)"><img src="/wp-content/plugins/mini-gravatar-cache/iava/'.md5(strtolower($count->comment_author_email)).'.jpg" alt="' . $count->comment_author . ' ('. $count->cnt . '层楼)" width="48px" height="48px"/></a><p>' . $count->comment_author . '</p></div></li>';
endforeach; endif;
?>
</ul>
</div>
<div class="content">
<?php the_content(); ?>
</div>
</div>
<div id="myads" class="sy-ad"></div>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<div class="post">哦!您要找的日志可能已经更换地址,重新搜索一下吧,或者点击<a title="Home" class="active" href="<?php echo get_option('home'); ?>/">这里</a>回首页看看吧</div>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

然后去后台新建一个页面,模板选择你新建的文件listpage.php。这样以后发上个月排行榜的图的时候,只要直接在后台编辑页面,就可以了。

对了还有下面的css代码,复制到你的主题的style.css文件中,根据自己主题的需要更改细节:

.listwall {
width:620px;}
.ffox_most_active li {
float:left;
height:60px;
list-style:none outside none;
margin-left:5px;
overflow:hidden;
padding-bottom:20px;
width:70px;
}
.ffox_most_active_img{
height:48px;
text-align:center;
width:65px;
}
.ffox_most_active p {
text-align:center;
font-size:13px;
width:70px;
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
}

日志信息 »

该日志于2010-11-20 12:26由 海天无影 发表在学习笔记分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下转载到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

34条评论▼点击进行评论


  1. Warning: copy(/home/wwwroot/haitian/blog/avatar/e79b68291d7cca7f06d4a71c11c1607a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    速度啊 不用插件吗


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      不用插件 直接代码 呵呵~
      额 那个代码放在function.php文件中 最好放在中间 不破换文件结构


  2. Warning: copy(/home/wwwroot/haitian/blog/avatar/e79b68291d7cca7f06d4a71c11c1607a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    杯具了 代码放入functions.php不行 出现错误啊


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 我的怎么正常的
      你的提示什么啊
      放在function.php中间 不要破坏前后结构


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/e79b68291d7cca7f06d4a71c11c1607a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        我不知道具体应该放在哪里!


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          额 就是 functions.php文件啊
          只有不破坏开头和结尾 还有其他函数的{}就可以啊


          • Warning: copy(/home/wwwroot/haitian/blog/avatar/e79b68291d7cca7f06d4a71c11c1607a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
            回复

            嗯 我再试试 要是不行我再问你 呵呵


  3. Warning: copy(/home/wwwroot/haitian/blog/avatar/ae1d9cb02574d579039efc62a447f2f3.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    你真勤奋,每个月都做我肯定会忘记


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 哪里 好几次 都是随缘同学提醒的
      然后改个数字 补上的


  4. Warning: copy(/home/wwwroot/haitian/blog/avatar/fb2142a1ebd9dd2d0dc5d012fd84ded5.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个真不错,晚上我就测试一下,看看效果啦。谢谢海天。 :cool:


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 客气客气啦~


  5. Warning: copy(/home/wwwroot/haitian/blog/avatar/0dcedda7123567217b5ce259e203a209.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    海天的貌似要比我繁琐点
    我不用动function.php嘛。。。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      我这个主要方便调用 你可以用在页面 也可以在侧边
      貌似将代码直接加载那个页面里 应该也是可以的 下次我试试


  6. Warning: copy(/home/wwwroot/haitian/blog/avatar/3e65add30eaf3de5c1955d1f309c7574.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个代码我们zb也有,哈哈!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 zb?


  7. Warning: copy(/home/wwwroot/haitian/blog/avatar/d53e3eb8cf43fc1b9101ae2c247319a1.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    是哪个排行榜啊?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 我博客右上角啊~


  8. Warning: copy(/home/wwwroot/haitian/blog/avatar/c4668a51a1479f6c344c7b79636c2236.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我没看到有排行


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 右上角 右上角啦


  9. Warning: copy(/home/wwwroot/haitian/blog/avatar/5e29ff2eb17b2447c034c302eff3a6e1.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    恩 zb好像也有哦!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 zb是指zblog吗


  10. Warning: copy(/home/wwwroot/haitian/blog/avatar/32771531dda6fb833937f8a89d24553e.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    看了下效果还不错哦。改天也折腾个玩玩。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 ok~


  11. Warning: copy(/home/wwwroot/haitian/blog/avatar/91d4b8b766d671885ca91df1529fd3db.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    排行榜,互动性会强点。


  12. Warning: copy(/home/wwwroot/haitian/blog/avatar/c338dbe71bccbcc6c35befd199894fbf.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    牛逼了 呵呵


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 仿的 呵呵~


  13. Warning: copy(/home/wwwroot/haitian/blog/avatar/45a320354734871df0f0c2b445c4b37d.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    电脑高手~~果然不同凡响


  14. Warning: copy(/home/wwwroot/haitian/blog/avatar/a726bd46c51dbbb580d8f609a3d2b3a1.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个很有带动力哟,不错!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      嘿嘿 可惜在右上角 很多人不知道


  15. Warning: copy(/home/wwwroot/haitian/blog/avatar/d94967b298c3fcfed3f8e5a6c5181f42.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个真得顶 :roll:


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      那是 你要不顶 就说不过去啦 呵呵~


  16. Warning: copy(/home/wwwroot/haitian/blog/avatar/8a696fb2b60f79867e39e7803303fc7a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    有阵子没折腾wordpress了,这个互动排行蛮好的,不过我那博客人气也不高,懒得去弄了。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 我弄的玩的~


  17. Warning: copy(/home/wwwroot/haitian/blog/avatar/b041fec6d9b41851a84ef29a4827c1d7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    11月我还没有上,再加把劲,呵呵!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      哈哈 加油~


  18. Warning: copy(/home/wwwroot/haitian/blog/avatar/870740f1294e031dfe7ef1cbb020cff2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我的水墙时间限制是一年的,然后只显示前面的70名左右哈。。

    嘿嘿。。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      1年 好长啊 呵呵~


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/870740f1294e031dfe7ef1cbb020cff2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        嘿嘿 ,水墙嘛,可以一周,一个月,一个季,和一年的。
        我设置为一年的。


  19. Warning: copy(/home/wwwroot/haitian/blog/avatar/870740f1294e031dfe7ef1cbb020cff2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    嘿嘿。再来踩海天一下哈。
    也提高下知名度哈。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      哈哈 欢迎~


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/870740f1294e031dfe7ef1cbb020cff2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        谢谢哈, :mrgreen:
        谢谢哈,又来了哈。


  20. Warning: copy(/home/wwwroot/haitian/blog/avatar/12b30bf0a5eb5ae5c4ff9a4f7a7ef691.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    用代码实现 换主题的时候就的忙活一阵子了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 就是把function.php里代码换个地方啊 很简单啊~


  21. Warning: copy(/home/wwwroot/haitian/blog/avatar/e5a2128fe5dbfa7c55ac78442853916d.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我一直觉得你这博客美化的越来越好看了,而且也有利于SEO


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 谢谢夸奖~


  22. Warning: copy(/home/wwwroot/haitian/blog/avatar/c73866955b6bea7caaa14ebc22a7c622.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    代码俺是看不懂了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      我晕 你看不懂?你是技术牛人啊~


  23. Warning: copy(/home/wwwroot/haitian/blog/avatar/bf12d703481f992fb051334a04f27c7b.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我最近想弄个水墙,哈哈


  24. Warning: copy(/home/wwwroot/haitian/blog/avatar/32f4c45a8e6a4285641133c301827f2e.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    :roll: 学习中,进步中


  25. Warning: copy(/home/wwwroot/haitian/blog/avatar/b7cd76b5fa13addd41763c74022b21c5.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    直接放代码就可以了?不需要插件么 ;-)


  26. Warning: copy(/home/wwwroot/haitian/blog/avatar/09e617601c68ad782fee4be6b64ed6b3.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我来看博主文章了,感谢分享哦!!1!


  27. Warning: copy(/home/wwwroot/haitian/blog/avatar/e79b68291d7cca7f06d4a71c11c1607a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我没有这个头像缓存插件mini-gravatar-cache所以不行的


  28. Warning: copy(/home/wwwroot/haitian/blog/avatar/a3aefb0fe7b234e21048df33b142289e.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    博主,牛人


  29. Warning: copy(/home/wwwroot/haitian/blog/avatar/90397210e69d04e9a6df1ccaef487222.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    不需要插件么 :razz:


  30. Warning: copy(/home/wwwroot/haitian/blog/avatar/681318b75d1f10993386c202366871e6.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    头晕啊

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

« 海天排行榜第二期风云人物随缘同学 祝我生日快乐 »