把下载这段代码扔进functions.php文件里
<?php function most_popular_posts($no_posts = 5, $before = '<li>', $after = '</li>', $show_pass_post = false, $duration='') { global $wpdb; $request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments"; $request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'"; if(!$show_pass_post) $request .= " AND post_password =''"; if($duration !="") { $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date "; } $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts"; $posts = $wpdb->get_results($request); $output = ''; if ($posts) { foreach ($posts as $post) { $post_title = stripslashes($post->post_title); $comment_count = $post->comment_count; $permalink = get_permalink($post->ID); $output .= $before . '<a href="' . $permalink . '" title="' . $post_title.'">' . $post_title . '</a> (' . $comment_count.')' . $after; } } else { $output .= $before . "None found" . $after; } echo $output; } ?>
调用代码:
<?php most_popular_posts(); ?>
可用参数包括文章数,每条文章前面(before =)和后面的内容(after)。
原文:http://paranimage.com/wordpress-most-commented-pots/
声明:本文采用 BY-NC-SA 协议进行授权,如无注明均为原创,转载请注明转自 你好!刘
本文地址:wordpress调用评论最多的文章
本文地址:wordpress调用评论最多的文章
发表评论