我正在尝试在自定义帖子类型中添加评论,并且我不想使用:
<?php wp_list_comments();?>
我想在左侧显示评论表单,在右侧显示评论。
我添加了以下代码:
<div class="comments">
<?php if (have_comments()) : ?>
<h2><?php printf(_nx('One response to “%2$s”', '%1$s responses to “%2$s”', get_comments_number(), 'comments title', 'sage'), number_format_i18n(get_comments_number()), '<span>' . get_the_title() . '</span>'); ?></h2>
<ol class="comment-list">
<?php wp_list_comments(['style' => 'ol', 'short_ping' => true]); ?>
</ol>
<?php if (get_comment_pages_count() > 1 && get_option('page_comments')) : ?>
<nav>
<ul class="pager">
<?php if (get_previous_comments_link()) : ?>
<li class="previous"><?php previous_comments_link(__('← Older comments', 'sage')); ?></li>
<?php endif; ?>
<?php if (get_next_comments_link()) : ?>
<li class="next"><?php next_comments_link(__('Newer comments →', 'sage')); ?></li>
<?php endif; ?>
</ul>
</nav>
<?php endif; ?>
<?php endif; // have_comments() ?>
<?php if (!comments_open() && get_comments_number() != '0' && post_type_supports(get_post_type(), 'comments')) : ?>
<div class="alert alert-warning">
<?php _e('Comments are closed.', 'sage'); ?>
</div>
<?php endif; ?>
<?php comment_form(); ?>
</div><!--End Comments-->
该表单可以正常工作,但是注释本身将一直显示,直到我添加以下内容:
<?php wp_list_comments();?>
但是很明显,表单和注释出现了两次。
有什么主意我想念的吗?
谢谢!