2016-08-15 4 views
1

私は少し問題があります。私のコメントは表示されません、私は私のcomments.phpをチェックしましたが、なぜその理由が表示されませんか?先週はすべてうまくいっていて、突然表示されませんでした。私のコメントは表示されていません

私のコードは私のポストのテンプレートに

<?php 

if (post_password_required()) { 
    return; 
} 
?> 

<div id="comments" class="comments-area"> 

    <?php 
    if (have_comments()) : ?> 
     <h2 class="comments-title"> 
      <?php 
       $comments_number = get_comments_number(); 
       printf('Comments:'); 
      ?> 
     </h2> 

     <ol class="comment-list"> 
      <?php 
       wp_list_comments(array(
        'style'  => 'ol', 
        'short_ping' => true, 
        'avatar_size' => 42, 
        'type' => 'comment' 
       )); 
      ?> 
     </ol> 

    <?php endif;?> 

    <?php 
     if (! comments_open() && get_comments_number() && post_type_supports(get_post_type(), 'comments')) : 
    ?> 
     <p class="no-comments"><?php _e('Comments are closed.', 'twentysixteen'); ?></p> 
    <?php endif; ?> 

    <?php 
     comment_form(array(
      'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">', 
      'title_reply_after' => '</h2>', 
     )); 
    ?> 

</div> 

である私が試した

<?php 

get_header(); ?> 

<div id="primary" class="content-area main-template-content-post"> 
    <main id="main" class="site-main" role="main"> 
     <?php single_blog_loop();?> 
     <?php comments_template();?> 
    </main> 

</div> 
<?php get_sidebar();?> 
<?php get_footer(); ?> 

comments.phpなどがありますが、それはうまくいきませんでした。何か不足していますか?私は答えをgoogledしかし、何も動作するようです。私は今朝からこれに固執している。どのような助けもありがとうございます、事前に感謝します。

+0

'get_header(); ?> 'be' <?php get_header(); ?> '? –

+0

ああ、それはここでそれをコピーすることを忘れてしまった。待ち、病気編集 – codeplus

+0

JSエラーはありますか?そうでなければ、PHPの部分の中でエラーを探す必要があります。 – Marcus

答えて

0

私は問題があるcomments.phpではないことを知りました。これは私のsingle_blog_loop()関数にたくさんのループがあるからです。投稿記事リストの投稿タイトルを取得するために使用するループの最後にwp_reset_queryを追加しました。うまくいきます。ここに私のコードがありますが、ちょっと面倒です。 I

<?php while (have_posts()) : the_post();?> 
     <h1 style="line-height: 40px;" class="heading"><?php the_title();?></h1> 
     <h4 style=" margin:0; display: inline-block;"><?php the_date();?></h4> 
     <?php if (get_comments_number() == 1) { 
       echo ' <h4 style="float:right; margin:0; display: inline-block;">' . get_comments_number() . " comment in this article</h4>"; 
      }elseif (get_comments_number() > 1) { 
       echo ' <h4 style="float:right; margin:0; display: inline-block;">' . get_comments_number() . " comments in this article</h4>"; 
      }else{ 
       echo ' <h4 style="float:right; margin:0; display: inline-block;">There are no comments in this article.</h4>'; 
      }?> 

     <?php the_content();?> 

     <div class="article-sidebar-container"> 
      <h4>You might also like:</h4> 

     <?php $article = new WP_QUERY(

      array(

       'post_type' => 'post', 
       'posts_per_page' => 5 

      ) 

     ); 

     while ($article->have_posts()) : $article->the_post();?> 

      <div class="sidebarWidget-article"> 

       <?php if (has_post_thumbnail()) {?> 
        <span style="padding-right: 10px;"><img src="<?php echo the_post_thumbnail_url();?>" width="50" height="50"><a href="<?php echo the_permalink();?>"><?php echo the_title();?></a> 
       <?php }else{?> 
        <span style="padding-right: 10px;"><img src="http://www.papayaleavestea.com/wp-content/uploads/2016/08/no-image-available-300x200.png" width="50" height="50"></span><a href="<?php echo the_permalink();?>"><?php echo the_title();?></a> 
       <?php }?> 
      </div> 

      <div class="pagination"></div> 

     <?php endwhile; 
     wp_reset_query(); 
     ?> 

     </div> 
     <?php if (is_singular('attachment')) { 
      // Parent post navigation. 
      the_post_navigation(array(
       'prev_text' => _x('<span class="meta-nav">Published in</span><span class="post-title">%title</span>', 'Parent post link', 'papayatea'), 
      )); 
     } elseif (is_singular('post')) { 
      // Previous/next post navigation. 
      the_post_navigation(array(
       'next_text' => '<span class="meta-nav" aria-hidden="true">' . __('', 'papayatea') . '</span> ' . 
        '<span class="screen-reader-text-next">' . __('Next post:', 'papayatea') . '</span> ' . 
        '<span class="post-title">%title</span>', 
       'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __('', 'papayatea') . '</span> ' . 
        '<span class="screen-reader-text-prev">' . __('Previous post:', 'papayatea') . '</span> ' . 
        '<span class="post-title">%title</span>', 
      )); 
     }?> 
     <div class="clearfix spacer pagination"></div> 
関連する問題