Php 仅向帖子作者显示WordPress评论
在一个新的WordPress模板中,我想定制single.php,以便只向文章作者显示评论列表 其他用户(来宾和其他帖子作者)应该看不到任何评论或空白 总之,帖子作者(登录时)可以在其帖子底部看到评论列表,但在其他作者撰写的帖子底部看不到任何评论 我应该对以下代码应用什么条件代码Php 仅向帖子作者显示WordPress评论,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,在一个新的WordPress模板中,我想定制single.php,以便只向文章作者显示评论列表 其他用户(来宾和其他帖子作者)应该看不到任何评论或空白 总之,帖子作者(登录时)可以在其帖子底部看到评论列表,但在其他作者撰写的帖子底部看不到任何评论 我应该对以下代码应用什么条件代码 <?php global $wpdb,$current_user; $limit = 10; //this is limit per day per user $comment_count = $wpdb-&g
<?php
global $wpdb,$current_user;
$limit = 10; //this is limit per day per user
$comment_count = $wpdb->get_var( $wpdb->prepare("
SELECT count(*)
FROM cxp_comments
WHERE comment_author = '%s'
AND comment_date >= DATE_SUB(NOW(),INTERVAL 1 DAY);"
,$current_user->user_login) );
if($comment_count < $limit): ?>
<h2 class="comments-title"> Want to get and review this product?</h2>
<form action="http://localhost/reviews/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
<p class="comment-amaz" style="display:none;"><input id="user-rank" name="user-rank" aria-required="false" class="" type="text" value="<?php echo do_shortcode('[mycred_my_ranking]'); ?>"></p>
<p class="comment-amazi" style="display:none;"><input id="user-points" name="user-points" aria-required="false" class="" type="text" value="<?php echo do_shortcode( '[mycred_my_balance wrapper="0" title_el="" balance_el=""]' ); ?>"> </p>
<p class="comment-form-comment">
<textarea id="comment" name="comment" placeholder="Insert your Amazon Public Profile Link" aria-required="true"></textarea></p>
<p class="form-submit"><input name="submit" id="submit" class="submit" value="Review this product!" type="submit"> <input name="comment_post_ID" value=" <?php global $post;
echo $post->ID; ?>" id="comment_post_ID" type="hidden">
<input name="comment_parent" id="comment_parent" value="0" type="hidden">
</p> </form>
<?php endif; ?>
<?php if($comment_count > $limit): ?>
<p>Exceeded comments limit for today. Please, come back tomorrow!</p>
<?php endif; ?>
检查用户是否通过以下方式登录:
然后使用以下命令获取用户登录:
然后通过以下方式获得作者登录:
最后,比较:
if($autLogin == $curLogin) wp_list_comments();
完整代码:
if(is_user_logged_in()){
$curUser = wp_get_current_user();
if(get_the_author_meta('user_login') == $curUser->user_login) wp_list_comments();
}
$autLogin = get_the_author_meta('user_login');
if($autLogin == $curLogin) wp_list_comments();
if(is_user_logged_in()){
$curUser = wp_get_current_user();
if(get_the_author_meta('user_login') == $curUser->user_login) wp_list_comments();
}