复制内容到剪贴板
代码:
<?php
//调用WP的配置文件,别小看这个文件哦,这里改成你的blog的路径.
require_once('site/wp-config.php');
//这个函数从中文工具箱中copy的
//调用wp-config.php文件的目的主要是使用他的db查询功能,可以自己写连接MYSQL部份,但是觉得没有必要.
//主要应用在$wpdb变量中
function get_recent_comments($no_comments = 5, $before = '
', $after = '', $show_pass_post = false) {
global $wpdb;
$request = "SELECT ID, comment_ID, comment_content, comment_author FROM $wpdb->posts, $wpdb->comments WHERE $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
if(!$show_pass_post) { $request .= "AND post_password ='' "; }
$request .= "AND comment_approved = '1' ORDER BY $wpdb->comments.comment_date DESC LIMIT
$no_comments";
$comments = $wpdb->get_results($request);
$output = '';
foreach ($comments as $comment) {
$comment_author = stripslashes($comment->comment_author);
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_excerpt =substr($comment_content,0,32);
$comment_excerpt = utf8_trim($comment_excerpt);
$permalink = get_permalink($comment->ID)."#comment-".$comment->comment_ID;
$output .= $before . '» ' . $comment_author . ': ' . $comment_excerpt . '...' . $after;
}
echo $output;
}
//中文截断完善函数
function utf8_trim($str) {
$len = strlen($str);
for ($i=strlen($str)-1; $i>=0; $i-=1){
$hex .= ' '.ord($str[$i]);
$ch = ord($str[$i]);
if (($ch & 128)==0) return(substr($str,0,$i));
if (($ch & 192)==192) return(substr($str,0,$i));
}
return($str.$hex);
}
//执行函数,输出结果,这里你可以去掉下面这行,通过包含本文件来调用get_recent_comments();函数。
get_recent_comments();
?>将以上代码保成一个php文件,放在任意目录,修改wp-config.php的路径就可以了,祝你成功!
我也不知道你具体要怎么使用,所以我也只能猜想你想这样~!