首页 > 技术随笔 > wordpress 侧边栏显示评论内容

wordpress 侧边栏显示评论内容

2010年9月25日

下午花了点时间,参照网上的改法。其实只需修改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;?>

admin 技术随笔

  1. 目前还没有任何评论.
  1. 目前还没有任何 trackbacks 和 pingbacks.