0

The following code:

echo '<ul>';
while ( $query->have_posts() ) {
    $query->the_post();

    $title = get_the_title();
    echo '<li>' . $title . comments_number() . '</li>';
}
echo '</ul>';

moves the comments ABOVE and outside of the <li> like this:

1 Comment 

Hello world!
0

1 Answer 1

3

You want to use get_comments_number() as that doesn't echo the results, while comments_number does echo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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