冰古blog » wordpress » 2005 » 03 » 17 » Top 10 Posts/Views

Top 10 Posts/Views

自己成功装了第一个(以前安装过一些插件,但还没成功过0_o!!)wordpress plugin-Top 10 Posts/Views,其实,WordPress的Plugin是很容易安装的,只要把Pluin放到特定的目录下,在后台激活就搞定的了.但这个Plugin需要改模板,改模板还没什么,但他写的安装指南有点模糊,而且有一点bug,故也花了一点时间.安装过程如下:
1、先用phpmyadmin在wordpress的数据库下运行此段sql:

create table mostAccessed
(
postnumber int not null,
cntaccess int not null,
primary key(postnumber),
unique id(postnumber)
);

请大家注意备份!!
2、把plugin上传到plugins目录中后,在后台激活,然后在模板index中加入以下代码(他说明模糊的地方就是这里了):

Open your index.php and find this line:
<?php } } else { // end foreach, end if any posts ?>

And place this line just above that:
<?php if ($p > 0) { add_count($p);}?>

Now place this code where you want your top10 posts to show up (outside the wp-loop):
<?php show_pop_posts(); ?>

<?php } } else { // end foreach, end if any posts ?>此句代码在模板的index中是找不到的???故安装没有成功!!
一番周折后留言里有人找到了放代码的地方:classic中是放在<?php endwhile; else: ?> 的前面,然后我举一反三得出default是放在<?php endwhile; ?>的前面(大家可以在自己的模板中找相应的位置),然后在需要显示Top10的地方加入如下代码就搞定了:<?php show_pop_posts(); ?>
安装后还有一个小bug,还没点击任何一篇blog时,会显示如下错误:

Warning: Invalid argument supplied for foreach() in /www/users/bingu.net/blog/wp-content/plugins/top10.php on line 67

这时,只要点击任何一篇blog后就能正常显示了!

这个plugin还附带了blog被点击数的一个小hack,
在index中找到<?php comments_popup_link(‘Comments (0)’, ‘Comments (1)’, ‘Comments (%)’); ?>
在这句代码周围某个地方加入<?php show_post_count($post->ID, $before="(Visited ", $after=" times)"); ?>就可以了!

5 Responses to “Top 10 Posts/Views”

  1. Bingu says:

    具体是怎样呢?

  2. Tony says:

    请问为什么我的top10链接都是主页的链接?

  3. Bingu says:

    谢谢提醒,我修改一下!!

  4. Antonio says:

    其实你还是没说清楚放哪。我觉得还是这个解释的清楚
    http://rwk.twbbs.org/archives/2005/04/03/52/

Leave a Reply to Antonio