仅向 post 作者显示 WordPress 评论
Show WordPress comments to the post author only
在新的 WordPress 模板中,我想自定义 single.php 以便仅向 post 作者显示评论列表。
其他用户(来宾和其他 post 作者)应该看不到任何评论或空白 space。
总而言之,post 作者(登录时)可以在他的 post 底部看到评论列表,但在 post 底部看不到任何内容其他作者。
我应该对以下代码应用什么条件代码?
<?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; ?>
这仅适用于前端。我不关心管理面板。
检查用户是否登录 is_user_logged_in()
:
if(is_user_logged_in())
然后使用 wp_get_current_user()
获取用户登录:
$curUser = wp_get_current_user();
$curLogin = $curUser->user_login;
然后使用get_the_author_meta()
获得作者登录:
$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();
}
在新的 WordPress 模板中,我想自定义 single.php 以便仅向 post 作者显示评论列表。
其他用户(来宾和其他 post 作者)应该看不到任何评论或空白 space。
总而言之,post 作者(登录时)可以在他的 post 底部看到评论列表,但在 post 底部看不到任何内容其他作者。
我应该对以下代码应用什么条件代码?
<?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; ?>
这仅适用于前端。我不关心管理面板。
检查用户是否登录 is_user_logged_in()
:
if(is_user_logged_in())
然后使用 wp_get_current_user()
获取用户登录:
$curUser = wp_get_current_user();
$curLogin = $curUser->user_login;
然后使用get_the_author_meta()
获得作者登录:
$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();
}