我正在使用comments\\u模板()function 在每篇文章的侧栏中重复我的评论模板。这是本项目的一项要求。
有人要求我在每个帖子的提要栏中只重复最近的三条评论。
我在这里到处寻找解决方案,但什么也找不到。
是否有一个函数可以弹出到我的函数中。php文件,只回显每个帖子最近的三条评论?
如果它可以包含一些jquery来添加一个“阅读更多”链接,打开其余的评论,那就太好了,但这不是必需的。
我正在使用comments\\u模板()function 在每篇文章的侧栏中重复我的评论模板。这是本项目的一项要求。
有人要求我在每个帖子的提要栏中只重复最近的三条评论。
我在这里到处寻找解决方案,但什么也找不到。
是否有一个函数可以弹出到我的函数中。php文件,只回显每个帖子最近的三条评论?
如果它可以包含一些jquery来添加一个“阅读更多”链接,打开其余的评论,那就太好了,但这不是必需的。
因为您正在使用comments_template()
函数来显示注释,它在内部调用注释。主题的php文件
在注释中。php文件,您应该有一个函数wp_list_comments()
使用一些参数。您必须再添加一个参数per_page
在该函数中,如下所示:
wp_list_comments( array(
\'style\' => \'ol\',
\'short_ping\' => true,
\'avatar_size\' => 56,
\'per_page\' => \'3\'
)
);
还有一种方法可以实现这一点,无需使用函数重写文件。php
在函数中添加以下代码。php文件。
add_filter(\'wp_list_comments_args\', \'override_args\', 10, 1);
function override_args($args)
{
$args = array(
\'style\' => \'ol\',
\'short_ping\' => true,
\'avatar_size\' => 56,
\'per_page\' => \'3\'
);
return $args;
}
如果您只想在帖子上显示最近的评论而不使用插件,请在主题的模板文件中使用以下代码:
<?php global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,50) // NUMBER OF CHARACTERS
AS com_excerpt FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts
ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
WHERE comment_approved = \'1\'
AND comment_type = \'\'
AND post_password = \'\'
ORDER BY comment_date_gmt
DESC LIMIT 3"; // NUMBER OF COMMENTS
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "\\n<ul>";
foreach ($comments as $comment) {
$output .= "\\n<li>"."<a href=\\"" . get_permalink($comment->ID) .
"#comment-" . $comment->comment_ID . "\\" title=\\"on " .
$comment->post_title . "\\">" .strip_tags($comment->comment_author)
.":<br/><div>" . strip_tags($comment->com_excerpt)
."</div></a></li>";
}
$output .= "\\n</ul>";
$output .= $post_HTML;
echo $output;
?>
在WordPress中,注释间距不起作用。当我使用  在间距注释中,WordPress会在前端显示这些内容。其他html标记正在工作,但此标记不工作<如有任何建议,我们将不胜感激。