';
yang_widget_title($args, $instance, '', $this->id_base);
?>
$number,
'offset' => 0,
));
foreach ($myposts as $post): ?>
post_title)) ?>
$number,
'offset' => 0,
'orderby' => 'rand',
));
foreach ($myposts as $post): ?>
post_title)) ?>
';
}
public function update($new_instance, $old_instance)
{
$instance = array();
$instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : '';
$instance['number'] = (!empty($new_instance['number'])) ? (int) $new_instance['number'] : 6;
/* `days` 已废弃:旧实现拿它当「最近 N 天发布」的时间窗,
* 那正是热点只显示一条的根因。这里不再保存,
* 老实例里残留的 days 值会在下次保存时被丢掉。 */
return $instance;
}
public function form($instance)
{
$title = !empty($instance['title']) ? $instance['title'] : '';
$number = !empty($instance['number']) ? $instance['number'] : '6';
?>
'; foreach ($comments as $comment) { $link = get_comment_link($comment->comment_ID); $author = get_comment_author($comment->comment_ID); $post_title = get_the_title($comment->comment_post_ID); if ($post_title === '') { // 标题为空时(极少见)用「无标题」占位,不留空白 $post_title = __('无标题', 'kratos'); } echo '- ';
// ── 头像(左侧,圆形)──
if ($show_avatar) {
echo '';
echo get_avatar($comment->comment_author_email, $avatar_size, '', '', array(
'class' => 'avatar yang-avatar',
'extra_attr' => 'loading="lazy"',
));
echo '';
}
echo '
';
// ── 主体:评论摘要 ──
if ($show_excerpt) {
$text = $this->excerpt($comment->comment_content, $excerpt_length);
if ($text !== '') {
/* 整段链接到该评论锚点 —— 侧栏空间小,用户更容易点中的
* 是"这段文字"而不是下方小字。 */
echo '' . esc_html($text) . '';
}
} else {
/* 关掉摘要时,主体的位置留给「作者 + 文章」,
* 否则整条会变成只有一行小字,视觉上太轻。 */
echo ''
. esc_html(sprintf(
/* translators: 1: comment author, 2: post title */
__('%1$s 评论了《%2$s》', 'kratos'),
$author,
$post_title
))
. '';
}
/* ── 元信息行:作者 · 时间 · 文章标题 ──
*
* 🔴 这里**不拼成句子**(不像插件那样塞一个 "on"):
* 中文里「作者 在 文章 中评论」这种句式一旦走 i18n 字符串,
* 语序、量词、标点全都要重新适配;拆成三段各自独立,
* 任何语言下都不会错位。 */
echo '';
echo '' . esc_html($author) . '';
echo '·';
echo '';
echo '·';
echo ''
. esc_html($post_title) . '';
echo ' ';
echo ' '; // .yang-comment-body
echo ' ';
}
echo '
'; echo '