Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

comment_form() function doesn't work WordPress

  • SOLVED

I currently am using the old school code for adding comments in comments.php, but I want to clean things up and modernize the site by replacing all the code with this:

<?php comment_form(); ?>

I put it into the comments.php file. The form for entering the comment works fine, but no actual comments appear. All the comments are approved (I go into wp_admin to do that), yet all I ever see is the form for adding a new comment, I never see any actual comments.

Once I revert back to my old code the comments show up again. It's my understanding that the single line of code above is all I need for a basic commenting system, and I've read the codex and tutorials on the web and it confirms that it's the only required bit of code.

Can anyone help? Thanks!

Answers (3)

2012-01-10

Jurre Hanema answers:

This is the "new school" comments.php template I almost always base my code upon:


<?php

if(!empty($_SERVER['SCRIPT_FILENAME']) && basename($_SERVER['SCRIPT_FILENAME']) == 'comments.php')
die();


function comment_callback($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;

?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<?php
echo get_avatar($comment, 70, get_bloginfo('template_directory').'/images/default-gravatar.png');
?>

<div class="comment-text">
<cite class="comment-author"><?php comment_author_link(); ?> schreef:</cite>
<?php comment_text(); ?>
</div>
<?php
}


if(post_password_required())
{
?>
<p class="nocomments">Voer het wachtwoord in om reacties te kunnen bekijken.</p>
<?php
return;
}


if(get_post_status(get_the_ID()) != 'publish')
{
?>
<p class="nocomments">Reacties worden actief op het moment dat de post wordt gepubliceerd.</p>
<?php
return;
}


if(have_comments())
{
?>
<ul class="commentlist">
<?php wp_list_comments(array('style' => 'ol', 'callback' => 'comment_callback')); ?>
</ul>
<?php

if(get_comment_pages_count() > 1 && get_option('page_comments'))
{
?>
<div class="comment-navigation">
<span class="nav-previous"><?php previous_comments_link('&laquo; Oudere reacties'); ?></span>
<span class="nav-next"><?php next_comments_link('Nieuwere reacties &raquo;'); ?></span>
</div> <!-- .navigation -->
<?php
}
} else
{
// this is displayed if there are no comments so far

if(!comments_open())
{
?>
<p class="nocomments">Reacties zijn gesloten.</p>
<?php
} else
{
?>
<p class="nocomments">Er zijn nog geen reacties.</p>
<?php
}
}


// Display the comment form

comment_form(
array(
'label_submit' => 'Reageer!',
'title_reply' => 'Voeg een reactie toe',
'comment_notes_after' => null
)
);

?>


Maybe you can use it as an example.


John Buchmann comments:

Thanks so much for your sample code. It works for me and I'll use it as a base. It's hard to believe that all the documentation about the "new" way to do comments doesn't mention all the extra code.

2012-01-10

Julio Potier answers:

Hello can you post your old school code, thank you (please use code tags)

2012-01-10

Kailey Lampert answers:

comment_form() will only show the comment form.

You'll probably want to use get_comments() to retrieve all the comments, then loop through them to display them how you want.