php - 如何为 WordPress 自定义 PHP 模板上的特定帖子调用 comment_form()
问题描述
我正在修改一个模板文件,该文件循环遍历许多类似于 WordPress 中的存档页面的帖子。在该输出上,我可以显示已使用 get_comments 和 wp_list_comments 提交的评论。但是,我无法终生获得要输出的评论表。我已经尝试了许多不同种类的comment_form() 与args 提交page_id 但无济于事我要么打破页面,要么它只是没有出现。评论绝对是开放的,评论是可能的,但只是没有显示在页面上。
comment_form($featuredposts[$articlePageNo]->ID);
不会破坏我的页面,但会以没有形式返回。
comment_form(post_id => $featuredposts[$articlePageNo]->ID);
打破页面。我认为这可能是由于防止在 WordPress 中的非单个页面上显示 comment_form,但我似乎无法隔离如何告诉 WordPress 可以在我的页面上执行此操作。
comment_form($featuredposts[$articlePageNo]->ID); //ID is the post ID from my loop.
//This works for displaying the already submitted comments:
//Gather comments for a specific page/post
$comments = get_comments(array(
'post_id' => $postIDD,
'status' => 'approve' //Change this to the type of comments to be displayed
));
//Display the list of comments
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);
解决方案
comment_form()
实际上将 post id 作为第二个参数,如Developer Documentation中所述。(如果您不提供帖子 ID,则使用当前页面的帖子 ID)
所以尝试将 ID 作为第二个参数传递,如下所示:
comment_form(null, $featuredposts[$articlePageNo]->ID);
推荐阅读
- c# - 为什么解密后的字符串与输入的字符串不匹配?
- javascript - 如何读取同一行中的下一个值?
- c# - 如何从我的用户控件访问 label.Text
- puppet - puppetserver 作为另一个 puppetserver 的客户端
- ruby-on-rails - will_paginate 将关系误认为是数组
- r - rbind 基于列中匹配值的数据
- python-3.x - 术语“conda”未被识别为 cmdlet 的名称
- eclipse - 标题栏的Eclipse背景颜色
- sorting - 快速排序的最坏情况复杂性改进,无需将其转换为 mergsort
- python - 泛洪填充 NumPy Array `numpy.ndarray`,即为元素分配新值并更改相同值的相邻元素