如何显示对wordpress评论的回复?

我有评论,每条评论可以有任意数量的回复。 在评论之后,但在回复之前,我想输出有多少回复。 我想到了两种替代方法:</ p>


  1. (更多参与编码,但需要较少的wordpress和数据库知识)
    制作一个数组 用字符串和另一个用int。 两个数组的每个位置对应于注释/答复结构中的嵌套级别。 在输出注释时,检查您所在的嵌套级别或“$ depth”并“退出”或输出存储在数组中的信息,直到相同的嵌套级别。 然后添加当前嵌套级别的信息,当然更新上面一个嵌套级别的int来计算当前注释。

    • 有些涉及,我的PHP技能或调试工具不是很好所以这需要几个小时到 做。</ p> </ li>
    • (快速,但必须在wordpress中找到一些支持/功能,给我我想要的东西) 只需在wordpress中找到一些显示/返回数字的函数 回复评论(包括嵌套评论)</ p> </ li> </ ol> </ div>

展开原文

原文

I have comments and each comment can have any number of replies. After a comment, but before the replies, I want to output how many replies there are. I have thought of two alternative ways to do this:

  1. (more involved in coding, but requires less knowledge of wordpress and the database) Make an array with strings and another with ints. Each position of both arrays corresponds to a nesting level in the comment/reply structure. When outputting a comment check what nesting level, or "$depth" you're on and "retire", or output, the information stored in the arrays up and until the same nesting level. Then add information of the current nesting level and of course update the int that's one nesting level above to count the current comment. -- Somewhat involved, my php skills or debugging tools are not great so this would take a couple of hours to do.

  2. (quick but must find some support/function in wordpress that gives me what I want) Just find some function in wordpress that displays/returns the number of replies that a comment has (including nested comments)

dongmuyuan3046
dongmuyuan3046 您应该能够在MySQL查询中执行此操作。像SELECTCOUNT(*)FROMreply_tableWHEREcomment_id={$this_id};
9 年多之前 回复

3个回答



我用函数完成了同样的事情</ p>

  function child_comment_counter($ id)  {
global $ wpdb;
$ query =“SELECT COUNT(comment_post_id)AS count FROMwp_comments WHEREcomment_approved = 1 ANDcomment_parent =”。$ id;
$ children = $ wpdb-&gt; get_row ($ query);
return $ children-&gt; count;
</ code> </ pre>

} </ p>

以及输出它的实际代码 :</ p>

 &lt;?php echo“(”。child_comment_counter($ comment-&gt; comment_ID)。“)”;  ?&gt; 
</ code> </ pre>
</ div>

展开原文

原文

I accomplished this same thing with a function

function child_comment_counter($id){
global $wpdb;
$query = "SELECT COUNT(comment_post_id) AS count FROM `wp_comments` WHERE `comment_approved` = 1 AND `comment_parent` = ".$id;
$children = $wpdb->get_row($query);
return $children->count;

}

and the actual code to output it:

<?php echo "( ". child_comment_counter($comment->comment_ID) . " )"; ?>



我认为wordpress中没有可用的功能。 所以你必须自己破解它。 像Imoda建议的那样,使用可以用$ wpdb完成的Sql查询。 你可能想看一个类似的问题。 https://wordpress.stackexchange.com/questions/16457/count-parent-comments- 单独回复 </ p>
</ div>

展开原文

原文

I think there is not an available function in wordpress which does this. so you will have to hack it yourself. like Imoda suggests, use Sql query which can be done with $wpdb. there is a similar question you may want to take a look. https://wordpress.stackexchange.com/questions/16457/count-parent-comments-replies-separately



可能有一个插件可以执行此操作:</ p>

http://wordpress.org/extend/plugins/gregs-show-total-conversations/ </ p>
</ div>

展开原文

原文

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐