March 30, 201115 yr Hey I've been trying to get this to work for a while now: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="entry"> <h3><?php the_title(); ?><span class="comment_count"><?php comments_number('No Comments','One Comment','% Comments'); ?></span></h3> <?php the_content(); ?> <div class="post_details"> <p>Author: <span class="author"><?php the_author(); ?>.</span></p> <p>Posted On: <span class="date_posted"><?php echo get_the_date(); ?></span></p> </div> </div> <!-- end entry div --> <h3>Comments</h3> <?php if($comments) : ?> <ul class="comments"> <?php foreach($comments as $comment) : ?> <div class="comment_meta"> <?php echo get_avatar(); ?> <span class="name"><a href="<?php comment_author_link(); ?>"><?php comment_author(); ?></a></span> <span class="date"><?php comment_date(); ?></span> </div> <?php if($comment->comment_approved == '0') : ?> <li class="comment_content"><p>Your comment is awaiting approval.</p></li> <?php endif; ?> <li class="comment_content"><?php comment_text(); ?></li> <?php endforeach; ?> </ul> <?php else : ?> <p>No comments currently for this post.</p> <?php endif; ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php comment_form(); ?>] Can anyone see a fault with the code as all that's ever returned is 'No comments currently for this post.' Or is this method now depreciated with the use of wp_list_comments(); ? Thanks, Adam. Edited March 30, 201115 yr by AdamConder
March 30, 201115 yr This line: <?php if($comments) : ?> I can't see any point in the code before that where the $comments variable is set.
March 30, 201115 yr Author I was thinking the same, but everywhere I've looked is the same. Surely need to store a SQL statement inside and check if anything has been returned? Or is $comments a global variable that wp understands?
March 30, 201115 yr I was thinking the same, but everywhere I've looked is the same. Surely need to store a SQL statement inside and check if anything has been returned? Or is $comments a global variable that wp understands? I think $comment is a global variable, not $comments. You could try using have_comments() to perform the check for comments - http://codex.wordpress.org/Function_Reference/have_comments
March 30, 201115 yr Author Problem now is how can I specify the post id? It's returning all comments something like: <?php $comments = get_comments($post->ID); ?>
March 30, 201115 yr Problem now is how can I specify the post id? It's returning all comments something like: <?php $comments = get_comments($post->ID); ?> Almost, I think it should be: <?php $comments = get_comments(get_the_ID()); ?> Ref: http://codex.wordpress.org/Function_Reference/get_the_ID Edited March 30, 201115 yr by andyl
March 30, 201115 yr Author This fixed it: <?php $post_id = $post->ID; ?> <?php $comments = get_comments(array('post_id' => $post_id)); ?>
Create an account or sign in to comment