wordpress 侧边栏显示评论内容
下午花了点时间,参照网上的改法。其实只需修改default-widget.php。
function utftrim($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);
}
if ( $comments ) : foreach ( (array) $comments as $comment) :
$comment_content = strip_tags($comment->comment_content);
$comment_content = stripslashes($comment_content);
$comment_content = preg_replace(’/\[qu(.(?!\[\/quote]))+.\[\/quote]/si’, ”, $comment_content);
$comment_content = preg_replace(’/\s*:em\d\d:\s*/si’,”, $comment_content);
$comment_excerpt = substr($comment_content,0,30);
$comment_excerpt = utftrim($comment_excerpt);
echo ‘‘ . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x(’%1$s : %2$s’, ‘widgets’), get_comment_author_link(), ”.$comment_excerpt . ‘…’) . ‘
‘;
endforeach; endif;?>
最新评论