在自定义Wordpress主题上恢复评论功能

时间:2014-09-16 12:47:50

标签: php wordpress comments

这是我在这里的第一篇文章,我试图确保它符合发布指南。如果我错过任何事情,请提前道歉!

我的网站评论功能出现问题。该网站位于:http://chrislee.is/thinking-about。评论数量显示在每篇帖子下方,以及提交您自己的评论的提示,但评论的内容未显示。对于有1条评论未显示的特定帖子,请参阅此处:http://chrislee.is/thinking-about/saying-yes-more/

主题大量改编自Blogum,代表了我第一次尝试构建自定义主题。我有一个单独测试和保存每个更改的政策,以确保我可以在出现问题时回溯我的步骤,但在某个地方,我已经搞砸了评论。

以下是评论和单个帖子(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 &raquo;</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 &raquo;</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(); ?>

提前感谢您提供的任何见解:)

2 个答案:

答案 0 :(得分:0)

您是否阅读过wordpress网站上的Display Comments for a Specific Page/Post。它似乎暗示您需要将一系列评论传递给&#39; wp_list_comments&#39;。

wp_list_comments(array('callback' => 'commentlist'));

我在这里及其周围粘贴一两个var_dumps(),这样你就可以看到可用的数据了。

答案 1 :(得分:0)

如果我猜错了,你的问题就在这里:

wp_list_comments(array('callback' => 'commentlist'));

来自食典委:

  

&#39;回调&#39;
  (回调)用于打开和显示每个注释的自定义函数的名称。 使用此功能可以调用自定义函数来显示每条评论,绕过所有内部WordPress功能。用于自定义注释显示,以便对HTML布局进行极端更改。请注意,您的回调必须包含开头<div><ol><ul>标记(与样式参数对应),但不包括结束标记。 WordPress将自动提供结束标记,或者您可以使用end-callback来覆盖此默认值。回调与end-callback分开,以便于分层注释。请谨慎使用。

如果没有评论显示,我的猜测是你可能没有一个名为&#39;评论列表的功能&#39;定义在任何地方。

尝试将其更改为:

wp_list_comments(array('style'=>'ol', 'type'=>'comment'));