我在Wordpress中使用comment_form(),评论表单正在显示,但已批准的实际评论不是:
这是我的代码
<?php
$comments_args = array(
// remove "Text or HTML to be displayed after the set of comment fields"
'comment_notes_after' => 'Note: Comments are moderated so will not publish immediately.',
// change "Leave a Reply" to "Comment"
'title_reply'=>'What did you think of this story? Please share a comment.',
// change the post comment button
'label_submit' => __( 'Submit your comment' ),
);
comment_form($comments_args);
?>
我取消选中并选中设置下的正确选项 - &gt;讨论
除了comment_form,我还需要另一个电话吗? 这是一种自定义帖子类型会有所不同吗?
感谢您的帮助。
答案 0 :(得分:1)
尝试使用二十四个主题中的comments.php文件。如果它有效,很可能nishant是正确的,可能没有为您的帖子类型激活评论。 TwentyFourteen的comments.php也是评论最佳实践的一个很好的例子。您可以根据其他代码进行检查,如果有的话。
答案 1 :(得分:-1)
如果它是自定义帖子类型,则没有任何区别,但是您应该在function.php中声明对自定义帖子类型的评论支持,其中您有自定义帖子类型的书面参数。例如'supports' => array( 'title' ,'author','comments')
。
并在single-post-type.php中使用这样写<?php comments_template( '', true ); ?>
来调用comments.php。
并将您的comments.php作为备份,并将其替换为以下内容 -
<?php
/**
* The template for displaying Comments
*
* The area of the page that contains both current comments
* and the comment form. The actual display of comments is
* handled by a callback to twentytwelve_comment() which is
* located in the functions.php file.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/
if ( post_password_required() )
return;
?>
<div id="comments" class="comments-area">
<?php // You can start editing here -- including this comment! ?>
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'twentytwelve' ),
number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
?>
</h2>
<ol class="commentlist">
<?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>
</ol><!-- .commentlist -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
<nav id="comment-nav-below" class="navigation" role="navigation">
<h1 class="assistive-text section-heading"><?php _e( 'Comment navigation', 'twentytwelve' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'twentytwelve' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'twentytwelve' ) ); ?></div>
</nav>
<?php endif; // check for comment navigation ?>
<?php
/* If there are no comments and comments are closed, let's leave a note.
* But we only want the note on posts and pages that had comments in the first place.
*/
if ( ! comments_open() && get_comments_number() ) : ?>
<p class="nocomments"><?php _e( 'Comments are closed.' , 'twentytwelve' ); ?></p>
<?php endif; ?>
<?php endif; // have_comments() ?>
<?php //comment_form(); ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond" class="comment-respond">
<h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>
<div id="cancel-comment-reply">
<p class="small"><?php cancel_comment_reply_link( __("Cancel Reply", "bonestheme") ); ?></p>
</div>
<div class="cancel-comment-reply">
<?php cancel_comment_reply_link(); ?>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post 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 wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out »</a></p>
<?php else : ?>
<p class="comment-notes">Your email address will not be published. Required fields are marked <span class="required">*</span></p>
<p class="comment-form-author"><label for="author">Name <?php if ($req) echo '<span class="required">*</span>'; ?></label>
<input type="text" name="author" id="author" value="<?php //echo $comment_author; ?>" size="22" tabindex="1" /></p>
<p class="comment-form-email"><label for="email">Mail <?php if ($req) echo '<span class="required">*</span>'; ?></label>
<input type="text" name="email" id="email" value="<?php //echo $comment_author_email; ?>" size="22" tabindex="2" /></p>
<p class="comment-form-url"><label for="url">Website</label>
<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" /></p>
<?php endif; ?>
<!--<p class="form-allowed-tags"><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
<p class="comment-form-comment"><p><label for="comment">Comment <?php if ($req) echo '<span class="required">*</span>'; ?></label>
<textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
<p class="form-submit"><input name="submit" type="submit" id="submit" tabindex="5" value="Post Comment" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
</div>
<?php endif; // if you delete this the sky will fall on your head ?>
</div><!-- #comments .comments-area -->
注意 - 请根据您的css更改班级名称和ID