比这篇新的文章:
Codee#5781
比这篇旧的文章: Codee#5777
作者: mengzehe, 点击245次, 评论(0), 收藏者(0), , 打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: Codee#5777
获取 最多沙发党 函数
语言: PHP, 标签: 沙发 2009/09/07发布 12个月前更新作者: mengzehe, 点击245次, 评论(0), 收藏者(0), , 打分:
PHP语言: 获取 最多沙发党 函数
01 <!-- 获取 最多沙发党 函数 -->
02 <?php
03 function sofa(){
04 global $wpdb;
05
06 $first_commentors = array(); //初始化沙发党数组
07
08 $q = "SELECT DISTINCT comment_post_id FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1'";
09 $have_comment_post_ids = $wpdb->get_results($q); //获取有留言的日志ID
10 foreach ($have_comment_post_ids as $have_comment_post_id){
11 $q = "SELECT comment_author FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1' AND comment_post_id = $have_comment_post_id->comment_post_id order by comment_date limit 1";
12 $first_comment = $wpdb->get_results($q); //获取沙发党
13 array_push($first_commentors,$first_comment[0] -> comment_author); //添加进沙发党数组
14 }
15
16 $first_commentors = (array_count_values ($first_commentors)); //统计
17 arsort($first_commentors); //排序
18
19 $first_commentors_author = array_keys($first_commentors);//获取沙发党名字
20
21 $output = ""; //初始化输出字符串
22 $output .= '<ul class="wp_sofa">';
23 for($i=0; $i<3; $i++){
24 $title="";
25 if($i==0)$title = "状元:";
26 if($i==1)$title = "榜眼:";
27 if($i==2)$title = "探花:";
28 $q = "SELECT comment_author_url FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1' AND comment_author_url !='' AND comment_author = '$first_commentors_author[$i]' limit 1";
29 $first_comment_url = $wpdb->get_results($q); //获取沙发党的博客
30 if($first_comment_url){
31 $output .= '<li><a href="' . $first_comment_url[0] -> comment_author_url . '" title="' . $first_commentors_author[$i].'">' . $title.$first_commentors_author[$i] . '</a>(' . $first_commentors["$first_commentors_author[$i]"].')</li>';
32 } else {
33 $output .= '<li>' . $title.$first_commentors_author[$i] . '('.$first_commentors["$first_commentors_author[$i]"] . ')</li>';
34 }
35 }
36 $output .= '</ul>';
37 echo $output;//输出沙发党前三甲
38 }
39 ?>
02 <?php
03 function sofa(){
04 global $wpdb;
05
06 $first_commentors = array(); //初始化沙发党数组
07
08 $q = "SELECT DISTINCT comment_post_id FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1'";
09 $have_comment_post_ids = $wpdb->get_results($q); //获取有留言的日志ID
10 foreach ($have_comment_post_ids as $have_comment_post_id){
11 $q = "SELECT comment_author FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1' AND comment_post_id = $have_comment_post_id->comment_post_id order by comment_date limit 1";
12 $first_comment = $wpdb->get_results($q); //获取沙发党
13 array_push($first_commentors,$first_comment[0] -> comment_author); //添加进沙发党数组
14 }
15
16 $first_commentors = (array_count_values ($first_commentors)); //统计
17 arsort($first_commentors); //排序
18
19 $first_commentors_author = array_keys($first_commentors);//获取沙发党名字
20
21 $output = ""; //初始化输出字符串
22 $output .= '<ul class="wp_sofa">';
23 for($i=0; $i<3; $i++){
24 $title="";
25 if($i==0)$title = "状元:";
26 if($i==1)$title = "榜眼:";
27 if($i==2)$title = "探花:";
28 $q = "SELECT comment_author_url FROM $wpdb->comments WHERE comment_type ='' AND user_id = 0 AND comment_approved = '1' AND comment_author_url !='' AND comment_author = '$first_commentors_author[$i]' limit 1";
29 $first_comment_url = $wpdb->get_results($q); //获取沙发党的博客
30 if($first_comment_url){
31 $output .= '<li><a href="' . $first_comment_url[0] -> comment_author_url . '" title="' . $first_commentors_author[$i].'">' . $title.$first_commentors_author[$i] . '</a>(' . $first_commentors["$first_commentors_author[$i]"].')</li>';
32 } else {
33 $output .= '<li>' . $title.$first_commentors_author[$i] . '('.$first_commentors["$first_commentors_author[$i]"] . ')</li>';
34 }
35 }
36 $output .= '</ul>';
37 echo $output;//输出沙发党前三甲
38 }
39 ?>
所有评论,共0条:( 我也来说两句)
代码
