我創建了一個WordPress的評論網站與我的博客模板的幫助。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; ?>
感謝您的閱讀! 丹尼爾
問什麼客人應該看到?沒有評論或與登錄用戶相同的評論? – 2014-10-30 15:38:02
他們應該看到與登錄用戶相同的評論。 – egolive 2014-10-30 17:45:42
當你定義'$ comments'時,你可以發佈嗎 – 2014-10-30 19:17:27