Home > php教程 > php手册 > body text

抓取网站第N条评论的作者

WBOY
Release: 2016-06-06 20:08:37
Original
1294 people have browsed it

今天声儿在上一篇文章中抢第100条评论没抢到,给了我一个灵感,就是抓取网站历史上第N条评论的作者,比如抓取第1000条评论的作者,也就是查询第1000条评论是谁发出的,找出谁是这个幸运之星~ 先上效果,(白色框框里面是鼠标放上去显示的title内容,也可以去小蝴蝶的

今天声儿在上一篇文章中抢第100条评论没抢到,给了我一个灵感,就是抓取网站历史上第N条评论的作者,比如抓取第1000条评论的作者,也就是查询第1000条评论是谁发出的,找出谁是这个幸运之星~
先上效果,(白色框框里面是鼠标放上去显示的title内容,也可以去小蝴蝶的留言板围观)


把如下代码扔到你想显示的地方即可
<?php $args = array(
	'order' => 'ASC',//排序orderby的默认值是comment_date_gmt,所以只需调整order为倒序即可实现从旧往新输出
	'number' => '1',//显示一条
	'offset' => 99,  //这里很重要,在本组函数中表示的意思是指在第一条评论之后99条的评论,也就是第100条 
	//'type' => 'comment', //如果你想仅仅统计不带pingbacks的评论,请把这句前面的//去掉 
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo('第100条:<a href="'.%20get_comment_link(%24comment->comment_ID).'" title="'.mysql2date('在Y-m-d说:',$comment->comment_date). strip_tags($comment->comment_content). '">'.$comment->comment_author.'</a>');
endforeach;
?>
Copy after login

用array是为了方便用注释给大家解释,如果大家喜欢短一点的,下面这段代码效果同上(是的,其实我就是想让文章更长一点,怎么地!)

<?php $comments = get_comments('number=1&offset=99&order=ASC');
foreach($comments as $comment) :
echo('第100条:<a href="'. get_comment_link($comment->comment_ID).'" title="'.mysql2date('在Y-m-d说:',$comment->comment_date). strip_tags($comment->comment_content). '">'.$comment->comment_author.'');
endforeach;
?>
Copy after login

好了,为了让这个功能派上用场,小蝴蝶即日起开展盖楼大赛(我好无聊哦),每第N000个幸运好基友都有机会....
上面省略号中的内容我想了很久无果,所以大家踊跃发言说说给什么福利比较好呢?
话说回来发言还是要发言的,但代码也是要看的哦,唔要本末倒置咗!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!