这是我的代码:
$output .=
'<li class="recentcomments recent-comment">
<div class="wbrc-header">
<span class="wbrc-header-avatar">' . get_avatar( $comment, 50/*avatar_size*/ ) . '</span>
<div class="wbrc-header-AD">
<span class="wbrc-header-author">' . $author . '</span>
<span class="wbrc-header-date">' . $date . '</span>
</div>
</div>
<div class="wbrc-body">
<span class="wbrc-body-comment">' . $comment_text . '</span>
</div>'.
if( ($key + 1) != $comments->count() ) {
echo '<hr>';
} .
'</li>';
在此行中-我要在所有“ li标记”中添加“ hr标记”-除了最后一个li-但此行有错误-我必须做什么?
if( ($key + 1) != $comments->count() ) {
echo '<hr>';
}
答案 0 :(得分:0)
您需要将条件移到串联之外。
// here i am using ternary operator for your condition.
$condition = (($key + 1) != $comments->count() ? '<hr>' : '');
然后,您可以像这样使用
:$output .=
'<li class="recentcomments recent-comment">
<div class="wbrc-header">
<span class="wbrc-header-avatar">' . get_avatar( $comment, 50/*avatar_size*/ ) . '</span>
<div class="wbrc-header-AD">
<span class="wbrc-header-author">' . $author . '</span>
<span class="wbrc-header-date">' . $date . '</span>
</div>
</div>
<div class="wbrc-body">
<span class="wbrc-body-comment">' . $comment_text . '</span>
</div>'.$condition. // change this part
'</li>';
将IF
条件与串联(.)
一起使用将产生"syntax error, unexpected 'if'"
。