[英]Restoring comment functionality on custom Wordpress theme
這是我在這里的第一篇文章,我已嘗試確保其與發布指南一致。 如果我錯過任何事情,提前致歉!
我的網站的評論功能遇到問題。 該站點位於: 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 »</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(); ?>
預先感謝您提供的任何見解:)
如果要冒昧地猜測一下,您的問題就在這里:
wp_list_comments(array('callback' => 'commentlist'));
從食典:
'打回來'
(回調)用於打開和顯示每個注釋的自定義函數的名稱。 使用此功能將使您的自定義函數被調用以顯示每個注釋,從而繞過這方面的所有內部WordPress功能 。 用於自定義注釋顯示,以極大地更改HTML布局。 請注意,您的回調必須包含開始<div>
,<ol>
或<ul>
標記(與style參數對應),但不包括結束標記。 WordPress將自動提供結束標記,或者您可以使用結束回調來覆蓋此默認值。 回調與結束回調是分開的,以促進分層注釋。 請謹慎使用。
如果沒有評論出現,我想您可能沒有在任何地方定義名為“ commentlist”的功能。
嘗試將其更改為此:
wp_list_comments(array('style'=>'ol', 'type'=>'comment'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.