Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My code is the following:

<?php get_header(); ?>
<div id="main-content">
    <section id="primary">
<!--    <h2 class="cat-title">Latest news</h2> -->
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <article class="post">
            <img src="">
            <h2 class="post-title"><?php the_title(); ?></h2>
            <?php the_content('Read More...'); ?>
            <div class="post-info">
                by <?php the_author(); ?>,
                at <?php the_time('l F d, Y'); ?></a>
            </div>
            <?php previous_post_link(); ?> / <?php next_post_link(); ?>
        </article>

        <?php endwhile; else: ?>
            <p><?php _e('No posts were found. Sorry!', 'magaziner'); ?></p>
        <?php endif; ?>
        <ol class="commentlist">
            <?php wp_list_comments(); ?>
        </ol>
        <?php comment_form(); ?>
    </section>

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

I see only the form, but the comments are not visible. What's wrong?

share|improve this question
    
Are there comments in the first place? –  Johannes Pille Mar 20 '13 at 18:31
    
I have comments in the database. –  robert Mar 20 '13 at 18:32
1  
I believe wp_list_comments needs to be inside the loop. If not, you need to pass an array of comments to it. You are doing neither of these. –  vancoder Mar 20 '13 at 18:42
1  
@vancoder, why not post it as an answer? A hint: If not inside the loop, get_comments() will return such an array to pass to wp_list_comments() –  Johannes Pille Mar 20 '13 at 18:54
    
I moved <?php wp_list_comments(); ?> to under </article> and nothing changed. –  robert Mar 20 '13 at 18:56

1 Answer 1

up vote 3 down vote accepted

I believe wp_list_comments needs to be inside the loop. If not, you need to pass an array of comments to it. You are doing neither of these.

Either move it inside your loop, or call get_comments() (as Johannes rightly points out) and pass the returned array from that into wp_list_comments as the second argument.

You also need to call comments_template() before trying to output your comments. You can pass this function the name of a file, or it will default to comments.php. This file will then be included. So, you should move your comments code into this separate file:

<?php get_header(); ?>
<div id="main-content">
    <section id="primary">
<!--    <h2 class="cat-title">Latest news</h2> -->
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <article class="post">
            <img src="">
            <h2 class="post-title"><?php the_title(); ?></h2>
            <?php the_content('Read More...'); ?>
            <div class="post-info">
                by <?php the_author(); ?>,
                at <?php the_time('l F d, Y'); ?></a>
            </div>
            <?php previous_post_link(); ?> / <?php next_post_link(); ?>
        </article>
    <?php comments_template(); ?>
        <?php endwhile; else: ?>
            <p><?php _e('No posts were found. Sorry!', 'magaziner'); ?></p>
        <?php endif; ?>



    </section>

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

In comments.php:

<ol class="commentlist">
    <?php wp_list_comments(); ?>
</ol>
<?php comment_form(); ?>
share|improve this answer
    
I did it, but nothing changed, the complete code: pastebin.com/ygAu3Tfq –  robert Mar 20 '13 at 18:58
    
I elaborated on my answer. –  vancoder Mar 20 '13 at 19:22
    
Thank you, it's working. I thought I need only wp_list_comments. –  robert Mar 20 '13 at 19:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.