所以,过了一段时间,我完全按照自己的意愿做了,我想分享一下会很好。
所以在functions.php
添加
function c_parent_comment_counter($pid,$uid){
global $wpdb;
$query = "SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE <code>comment_approved</code> = 1 AND <code>comment_post_ID</code> = $pid AND <code>user_id</code> = $uid AND <code>comment_parent</code> = 0";
$parents = $wpdb->get_row($query);
return $parents->count;
}
并且在
comments.php
global $current_user, $post;
$number_of_parents = c_parent_comment_counter($post->ID,$current_user->ID);
echo "parents: ".$number_of_parents;
if ( $number_of_parents >= 1 ) {
echo \'<nav class="withcomment">\';
comment_form( array( \'title_reply\' => __( \'Reply\' ) ) );
echo \'</nav>\';
} else {
echo \'<span class="withoutcomment">\' . comment_form( array( \'title_reply\' => __( \'Your opinion\' ) ) ) . \'</span>\';
}
?>
在中
style.css
.withcomment {
display: none;
}
这将计算用户添加了多少父注释,如果添加了一条或多条父注释,则会隐藏表单。如果为0,则显示表单。但是,当您单击“答复”按钮时,表单将显示,您可以答复任何评论。这不是防黑客的!!!