到这一轮为止,读者看完文章只能走人——没有评论区。这一篇先让评论显示出来,表单放到下一篇。
<?php if ( post_password_required() ) { return; } ?>
<div id="comments">
<?php if ( have_comments() ) : ?>
<h2><?php comments_number( '没有评论', '1 条评论', '% 条评论' ); ?></h2>
<ol class="comment-list">
<?php wp_list_comments( array( 'style' => 'ol' ) ); ?>
</ol>
<?php endif; ?>
<?php comment_form(); ?>
</div>
四块:密码保护时直接退出、有评论就显示数量、列出评论、放一个表单。
<?php comments_template(); ?>
放在正文后面、get_footer() 前面。这个函数会自动去找 comments.php,找不到就用 WordPress 自带的默认版。
have_comments():这篇有没有评论。comments_number():按数量输出不同文案,三个参数分别是 0 条、1 条、多条时的写法,多条时用 % 代表数字。wp_list_comments():把评论一条条列出来。comment_form():输出评论表单。现在评论能显示了。下一篇改表单的文案和字段。
本系列:迭代式建主题 · 目录(72 篇) | 上一篇 (24) | 下一篇 (26)