WordPress主题评论不显示问题求助(附代码与截图)
Hey there, let's figure out why your comments aren't showing up even after you've enabled the feature in settings. Looking at your single post template code and the scenario you described, here are the key fixes and checks to get your comments section working:
1. Fix the comments_template Call & HTML Structure
First, I notice a couple of issues with how you're calling the comments template and closing your HTML tags. This could be causing the comments section to render outside the visible layout or not load at all.
Here's a cleaned-up version of your single post template code with proper structure and corrected template call:
<?php get_header(); ?> <div class="container"> <div class="row"> <?php if(have_posts()){ while(have_posts()){ the_post(); ?> <div class="post p-3 m-3 bg-light"> <?php edit_post_link('<span class="float-right">Edit <i class="fa fa-edit"></i></span>'); ?> <h3> <a href="<?php the_permalink() ?>"> <?php the_title() ?> </a> </h3> <small class="post-author text-secondary mx-2"><i class='fa fa-user mx-1'></i><?php the_author_posts_link(); ?></small> <small class="post-date text-secondary mx-2"><i class="fa fa-calendar mx-1"></i><?php the_time('F j, Y') ?></small> <small class="post-comments text-secondary mx-2"><i class="fa fa-comments mx-1"></i><?php comments_popup_link('no comments', 'one comment', '% comments', 'comment-url', 'commenting is disabled'); ?></small> <?php the_post_thumbnail('', ['class' => 'img-fluid img-thumbnail d-block']); ?> <?php the_content(); ?> <hr> <span class='post-tags'> <i class='fa fa-tags'></i> <?php the_category(', ') ?> </span> <span class='d-block'> <?php if(has_tag()){ the_tags(); } else{ echo 'Tags: no Tags'; } ?> </span> </div> <?php } } ?> <div class="clearfix"></div> <div class="post-pagination py-3 my-2 mx-auto"> <span class="mx-3"><?php previous_post_link(); ?></span> <span class="mx-3"><?php next_post_link(); ?></span> </div> </div> <!-- Close the .row div properly --> <hr> <?php // Use the default comments.php in your theme root (remove the path unless it's in a subfolder) comments_template(); ?> </div> <!-- Close the .container div --> <?php get_footer(); ?> <!-- Don't forget to load the footer! -->
- I removed the custom path from
comments_template()because WordPress automatically looks forcomments.phpin your theme's root directory. Only add a path if you've placed the file in a subfolder (like/templates/comments.php). - Fixed the HTML tag nesting to ensure the comments section is inside your main container, not outside it.
2. Verify Individual Post Comment Settings
Even if you've enabled comments globally, double-check that the specific post allows comments:
- Edit the post in your WordPress dashboard.
- Click the Options dropdown in the top-right corner and make sure "Discussion" is checked.
- In the "Discussion" panel on the right, confirm that Allow comments is ticked.
3. Ensure Your Theme Has a Valid comments.php File
If your theme doesn't have a comments.php file, WordPress can't render the comments section. Here's how to fix this:
- Copy the
comments.phpfile from a default WordPress theme (like Twenty Twenty-One) into your theme's root directory. - You can customize the file later to match your theme's styling, but starting with the default will ensure the functionality works.
4. Check for CSS That Hides the Comments Section
Sometimes the comments section loads but is hidden by CSS. Use your browser's developer tools (F12) to:
- Search for elements with classes like
comments-areaorcomment-list. - Check if any CSS rules (like
display: noneorvisibility: hidden) are hiding these elements.
Final Steps
After applying these fixes, clear your WordPress cache (if you're using a caching plugin) and reload the post page. Your comments section should now appear if all settings are correct.
内容的提问来源于stack exchange,提问作者Mohamed Ragab

