admin管理员组文章数量:1415491
Im trying to display a comment box inside a foreach loop however the comment_form function outputs before anything else. Here is the code I'm trying. Everything is displaying, just not in the right place. Any ideas or diff methods?
// get comments
$achievment_post .= '<ol class="commentlist">';
//Gather comments for a specific page/post
$comments = get_comments(array(
'post_id' => $achievment->ID,
'status' => 'approve'
));
$achievment_post .= wp_list_comments(array(
'per_page' => 10, // Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the top of the list
), $comments);
$achievment_post .= '</ol>';
// comment box
$achievment_post .= comment_form($args , $achievment->ID);
Im trying to display a comment box inside a foreach loop however the comment_form function outputs before anything else. Here is the code I'm trying. Everything is displaying, just not in the right place. Any ideas or diff methods?
// get comments
$achievment_post .= '<ol class="commentlist">';
//Gather comments for a specific page/post
$comments = get_comments(array(
'post_id' => $achievment->ID,
'status' => 'approve'
));
$achievment_post .= wp_list_comments(array(
'per_page' => 10, // Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the top of the list
), $comments);
$achievment_post .= '</ol>';
// comment box
$achievment_post .= comment_form($args , $achievment->ID);
Share
Improve this question
asked Sep 4, 2019 at 14:36
Silvester VellaSilvester Vella
155 bronze badges
1 Answer
Reset to default 0This is because you're collecting the HTML in a variable before you output, but comment_form
does not return HTML, it immediatley renders.
So, eliminate the $achievement_post
variable, and output directly with echo
instead, and things will work more as you expect
本文标签: commentsNeed to output commentform() function inside a foreach loop
版权声明:本文标题:comments - Need to output comment_form() function inside a foreach loop 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745185668a2646673.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论