2016-05-24 10 views
1

新しいWordPressテンプレートでは、投稿者にコメントリストを表示するためにsingle.phpをカスタマイズしたいと思います。投稿者のみに表示WordPressへのコメント

他のユーザー(ゲストやその他の投稿者)にはコメントや空白が表示されません。

要約すると、投稿者(ログに記録されたとき)は、自分の投稿の一番下のコメントのリストを見ることができますが、他の著者が投稿した投稿の一番下のものは表示されません。

次のコードにはどのような条件付きコードを適用しますか?

<?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()でログインしている場合

答えて

1

チェック:次に

$curUser = wp_get_current_user(); 
$curLogin = $curUser->user_login; 

get_the_author_meta()と著者ログインを取得:

$autLogin = get_the_author_meta('user_login'); 

if(is_user_logged_in()) 

その後wp_get_current_user()を持つユーザーのログインを取得

最後に、比較:

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(); 
} 
関連する問題