我借助我的博客模板创建了一个wordpress评论网站。
问题是。如果我已登录,我只能看到已批准的评论。 但如果我像访客一样退出登记,我可以看到所有评论,包括所有未经授权的评论。
这是我的代码:
<?php if (!empty($post->post_password) && $_COOKIE['wp-postpass_'.COOKIEHASH]!=$post->post_password) : ?>
<p id="comments-locked">Please log in to see the comments.</p>
<?php return; endif; ?>
<?php if ($comments) : ?>
<?php
$author = array(
"highlight" => "highlight",
"email" => "YOUR EMAIL HERE",
"name" => "YOUR NAME HERE"
);
$numPingBacks = 0;
$numComments = 0;
foreach ($comments as $comment) {
if (get_comment_type() != "comment") { $numPingBacks++; }
else { $numComments++; }
}
$thiscomment = 'odd';
?>
<?php
if ($numPingBacks != 0) : ?>
<h3 class="comments-header"><?php _e($numPingBacks); ?> Trackbacks/Pingbacks</h3>
<ol id="trackbacks">
<?php foreach ($comments as $comment) : ?>
<?php if (get_comment_type()!="comment") : ?>
<li id="comment-<?php comment_ID() ?>" class="<?php _e($thiscomment); ?>">
<?php comment_type(__('Comment'), __('Trackback'), __('Pingback')); ?>:
<?php comment_author_link(); ?> on <?php comment_date(); ?>
</li>
<?php if('odd'==$thiscomment) { $thiscomment = 'even'; } else { $thiscomment = 'odd'; } ?>
<?php endif; endforeach; ?>
</ol>
<?php endif; ?>
<?php
if ($numComments != 0) : ?>
<h3 class="comments-header"><?php _e($numComments); ?> Comments</h3>
<ol id="comments">
<?php foreach ($comments as $comment) : ?>
<?php if (get_comment_type()=="comment") : ?>
<li id="comment-<?php comment_ID(); ?>" class="<?php
$this_name = $comment->comment_author;
$this_email = $comment->comment_author_email;
if (strcasecmp($this_name, $author["name"])==0 && strcasecmp($this_email, $author["email"])==0)
_e($author["highlight"]);
else
_e($thiscomment);
?>">
<div class="comment-meta">
<span class="comment-author"><?php comment_author_link() ?></span>,
<span class="comment-date"><?php comment_date() ?></span>:
</div>
<div class="comment-text">
<?php comment_text(); ?>
</div>
</li>
<?php if('odd'==$thiscomment) { $thiscomment = 'even'; } else { $thiscomment = 'odd'; } ?>
<?php endif; endforeach; ?>
</ol>
<?php endif; ?>
<?php else :
?>
<h3 class="comments-header noPandM">There are no comments!</h3>
<p class="noPandM">Write the first Comment!</p>
<br />
<?php endif; ?>
<?php if (comments_open()) : ?>
<div id="comments-form">
<h3 id="comments-header">Write a Comment</h3>
<p class="commentsSmall"> Your E-Mail will not be published. Required fields are marked. </p>
<br />
<?php if (get_option('comment_registration') && !$user_ID ) : ?>
<p id="comments-blocked">You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=
<?php the_permalink(); ?>">Login</a> to write a Comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<?php if ($user_ID) : ?>
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php">
<?php echo $user_identity; ?></a>.
<a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout"
title="Log out of this account">Logout</a>
</p>
<?php else : ?>
<p class="commentformlabel"><label for="author">Name<?php if ($req) _e(' (*)'); ?></label></p>
<p><input type="text" class="commentText" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" /></p>
<p class="commentformlabel"><label for="email">E-mail <?php if ($req) _e(' (*)'); ?></label></p>
<p><input type="text" class="commentText" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" /></p>
<p class="commentformlabel"><label for="url">Website</label></p>
<p><input type="text" class="commentText" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" /></p>
<?php endif; ?>
<br />
<p class="commentformlabel"><label for="comment">Comment</label></p>
<p><textarea name="comment" style="width:80% !important;" id="comment" rows="8"></textarea></p>
<br />
<p><button type="submit" name="submit" id="sub">Submit</button>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>"></p>
<?php do_action('comment_form', $post->ID); ?>
</form>
</div>
<?php endif; ?>
<?php else : ?>
<p id="comments-closed">Sorry, but the Comments are closed in this Area!</p>
<?php endif; ?>
感谢您的阅读! 丹尼尔
答案 0 :(得分:0)
我认为您的问题出在您要求发表评论的时候。
如果您使用的是get_comments()
,请尝试以下操作:
$args = array(
'status' => 'approve',
'post_id' => get_the_ID(),
);
$comments = get_comments( $args );
// pay attention for existing variables with the same name as defined here