这是我在这里的第一篇帖子,我已经尽力确保它符合发布指南。如果我错过了什么,请提前道歉!
我的网站的评论功能有问题。网站在这里:http://chrislee.is/thinking-about.每条帖子下面都会显示评论的数量,并提示您提交自己的评论,但没有显示评论的内容。对于有1条评论未显示的特定帖子,请参阅此处:http://chrislee.is/thinking-about/saying-yes-more/
该主题大量改编自Blogum,代表了我第一次尝试构建自定义主题。我有一个单独测试和保存每一个更改的政策,以确保如果出现问题,我可以重新开始,但在某个地方,我把评论搞砸了。
以下分别是注释和单个post(single.php)php文件:
<?php if ( comments_open() ) : ?>
<div id="comments">
<?php if ( post_password_required() ) : ?>
<p class="nopassword"><?php _e('This post is password protected. Enter the password to view any comments.'); ?></p>
</div><!-- #comments -->
<?php
/* Stop the rest of comments.php from being processed,
* but don't kill the script entirely -- we still have
* to fully load the template.
*/
return;
endif;
?>
<?php
// You can start editing here -- including this comment!
?>
<div class="comments_heading clear">
<div class="comment_qty"><?php
printf( _n('1 comment', '%1$s comments', get_comments_number()),
number_format_i18n( get_comments_number() ), '' );
?></div>
<div class="add_comment"><a href="#respond">Submit yours</a></div>
</div>
<?php if (have_comments()) : ?>
<div class="comment_list">
<ol>
<?php
wp_list_comments(array('callback' => 'commentlist'));
?>
</ol>
</div>
<?php endif; // end have_comments() ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond" class="clear">
<div class="respond_meta">Submit comment</div>
<div class="comment_form">
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p class="comment_message">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" onSubmit="return checkFields();">
<?php if ( $user_ID ) : ?>
<p class="comment_message">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 : ?>
<div class="user_data">
<p><input id="author" type="text" name="author" class="focus" onfocus="if(this.value=='Name') this.value='';" onblur="if(this.value=='') this.value='Name';" value="Name" tabindex="1" /></p>
<p><input id="email" type="text" name="email" class="focus" onfocus="if(this.value=='Email') this.value='';" onblur="if(this.value=='') this.value='Email';" value="Email" tabindex="2" /></p>
<p><input id="url" type="text" name="url" class="focus" onfocus="if(this.value=='Website') this.value='';" onblur="if(this.value=='') this.value='Website';" value="Website" tabindex="3" /></p>
</div>
<?php endif; ?>
<!--<p class="comment_message"><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
<div class="comment_field">
<textarea name="comment" class="focus" id="comment" cols="50" rows="10" tabindex="4" onfocus="if(this.innerHTML=='Comment') this.innerHTML='';">Comment</textarea>
</div>
<p class="comment_submit"><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
<?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>
</div>
<?php endif; // end ! comments_open() ?>
<!-- #comments -->
以及Single.php文件的注释部分:
<?php
// You can start editing here -- including this comment!
?>
<div class="comments_heading clear">
<div class="comment_qty"><?php
printf( _n('1 comment', '%1$s comments', get_comments_number()),
number_format_i18n( get_comments_number() ), '' );
?></div>
<div class="add_comment"><a href="#respond">Submit yours</a></div>
</div>
<?php if (have_comments()) : ?>
<div class="comment_list">
<ol>
<?php
wp_list_comments(array('callback' => 'commentlist'));
?>
</ol>
</div>
<?php endif; // end have_comments() ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond" class="clear">
<div class="respond_meta">Submit comment</div>
<div class="comment_form">
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p class="comment_message">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" onSubmit="return checkFields();">
<?php if ( $user_ID ) : ?>
<p class="comment_message">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 : ?>
<div class="user_data">
<p><input id="author" type="text" name="author" class="focus" onfocus="if(this.value=='Name') this.value='';" onblur="if(this.value=='') this.value='Name';" value="Name" tabindex="1" /></p>
<p><input id="email" type="text" name="email" class="focus" onfocus="if(this.value=='Email') this.value='';" onblur="if(this.value=='') this.value='Email';" value="Email" tabindex="2" /></p>
<p><input id="url" type="text" name="url" class="focus" onfocus="if(this.value=='Website') this.value='';" onblur="if(this.value=='') this.value='Website';" value="Website" tabindex="3" /></p>
</div>
<?php endif; ?>
<!--<p class="comment_message"><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
<div class="comment_field">
<textarea name="comment" class="focus" id="comment" cols="50" rows="10" tabindex="4" onfocus="if(this.innerHTML=='Comment') this.innerHTML='';">Comment</textarea>
</div>
<p class="comment_submit"><input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
<?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>
</div>
<?php endif; // end ! comments_open() ?>
<!-- #comments -->
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
提前感谢您提供的任何见解:)
您是否阅读了wordpress网站上特定页面/帖子的显示注释。这似乎表明您需要向"wplistcomments"传递一组注释。
wp_list_comments(array('callback' => 'commentlist'));
我会在这里及其周围放置一到两个var_dumps(),这样您就可以看到可用的数据。
如果我冒险猜测,你的问题就在这里:
wp_list_comments(array('callback' => 'commentlist'));
来自Codex:
"回调"
(callback)用于打开和显示每个注释的自定义函数的名称使用此功能将调用您的自定义函数来显示每条评论,从而绕过WordPress在这方面的所有内部功能。用于为HTML布局的极端更改自定义注释显示。请注意,回调必须包括打开的<div>
、<ol>
或<ul>
标记(与样式参数相对应),但不包括关闭的标记。WordPress将自动提供关闭标记,或者您可以使用结束回调来覆盖此默认值。回调与结束回调是分开的,以便于进行分层注释。小心使用。
如果没有显示任何注释,我猜您可能没有在任何地方定义名为"commentlist"的函数。
尝试将其更改为:
wp_list_comments(array('style'=>'ol', 'type'=>'comment'));