Title: Show comments code
Last modified: August 19, 2016

---

# Show comments code

 *  [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/)
 * I’m using ‘Fazio’ as my theme, and like most other themes, by default visitors
   must click “Comments” or “Show Comments” to view the comments. I went searching
   for the code to make all comments show up on all posts and found this:
 *     ```
       <?php
       $withcomments = 1; // force comments form and comments to show on front page
       comments_template();
       ?>
       ```
   
 * I’ve tried inserting it in index.php and home.php. I must be putting it in the
   wrong place though because it wont work.
 * Anyone have a solution for this? I would like comments to show up on all posts
   on the front posts page, AND when visitors click over in the “Categories” section
   to view posts by category.

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754128)
 * read this thread:
 * [http://wordpress.org/support/topic/how-do-you-make-comments-show-on-the-page?replies=5](http://wordpress.org/support/topic/how-do-you-make-comments-show-on-the-page?replies=5)
 *  Thread Starter [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754131)
 * I don’t have the popup_script() in header.php and the other suggestion doesn’t
   fit the theme. Below is my comments.php
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com)]_
 *  Thread Starter [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754137)
 * I just tried suggestion from this post: [http://wordpress.org/support/topic/show-comments-and-form-on-front-page?replies=2](http://wordpress.org/support/topic/show-comments-and-form-on-front-page?replies=2)
 * Didn’t work either. I put the first code at the top of index.php as suggested,
   then tried inserting the next piece of code everywhere it could go while reloading
   the page each time to see if it was working.
 * Am searching through the forums for answers now.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754153)
 * try to add ‘global $withcomments;’ to your snippet:
 *     ```
       <?php
       global $withcomments;
       $withcomments = 1; // force comments form and comments to show on front page
       comments_template();
       ?>
       ```
   
 *  Thread Starter [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754161)
 * ARGHHHHHH!!!
 * This is exactly what is in index.php
 *     ```
       <?php get_header(); ?>
       <div id="pagewrap">
       	<div id="page">
       		<div id="content">
   
       			<?php if ( have_posts() ) : ?>
       				<?php while ( have_posts() ) : the_post(); ?>
   
       					<?php get_template_part('dry/post.php'); ?>
   
       <?php
       global $withcomments;
       $withcomments = 1; // force comments form and comments to show on front page
       comments_template();
       ?>
   
       				<?php endwhile; ?>
   
       			<?php pagination(); ?>
   
       			<?php else : ?>
   
       				<p><?php get_template_part('dry/404'); ?></p>
   
       			<?php endif; ?>
   
       		</div><!-- end content
       ```
   
 * What am I doing wrong?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754190)
 * your theme has a template file **home.php **which shows the front page – make
   the edit there.
 *  [Santiago](https://wordpress.org/support/users/teleportz/)
 * (@teleportz)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754315)
 * In the home.php, categories.php, tags.php, or whatever place you want, find this
   code:
    `<?php require('dry/post.php'); ?>` Replace with:
 *     ```
       <?php require('dry/post.php'); ?>
       					<?php
       						$withcomments = 1;
       						comments_template(FALSE, TRUE);
       					?>
       ```
   
 *  Thread Starter [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754416)
 * IT WORKS!
 * Just to be safe is this correct:
 *     ```
       <?php get_header(); ?>
       <?php get_template_part('dry/slideshow'); ?>
   
       <div id="pagewrap">
       	<div id="page">
       		<div id="content<?php if(fazio_option('layout_sidebar_on_home') == 'off') : ?> fullwidth<?php endif; ?>">
       			<?php if ( have_posts() ) : ?>
   
       				<?php while ( have_posts() ) : the_post(); ?>
       					<strong><?php get_template_part('dry/post'); ?>
       <?php
       						$withcomments = 1;
       						comments_template(FALSE, TRUE);
       					?>
       </strong>
   
       				<?php endwhile; ?>
   
       			<?php pagination(); ?>
   
       			<?php else : ?>
   
       				<p><?php get_template_part('dry/404'); ?></p>
       			<?php endif; ?>
   
       		</div><!-- end content -->
       		<?php if(fazio_option('layout_sidebar_on_home') == 'on') : get_sidebar(); endif; ?>
       	</div><!-- end page -->
       </div><!-- end pagewrap -->
       <?php get_footer(); ?>
       ```
   
 * There is no “<?php require(‘dry/post.php’); ?> so I just put it there.
 *  [Santiago](https://wordpress.org/support/users/teleportz/)
 * (@teleportz)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754424)
 * Yes, that code should work.
 *  Thread Starter [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754440)
 * Thanks it works.
 * One more question and that should be it.
 * Is there a way to replace the “Leave a reply” form with a link that says “Leave
   a comment” instead? That way when visitors scroll down they will see everything
   in this order:
 * 1. The post.
    2. The comments. 3. A link that says “Leave a comment” – instead
   of a form.
 * Put simple: How would I replace the “leave a reply” form with a link instead?
 *  [Santiago](https://wordpress.org/support/users/teleportz/)
 * (@teleportz)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754484)
 * In fazio/comments.php, wrap all this code:
 *     ```
       <?php
       if(function_exists('comment_form')) :
       	comment_form(array(
       		'comment_notes_before' => '',
       		'comment_notes_after' => '',
       		'logged_in_as' => '',
       		'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8"></textarea></p>'
       	));
       else :
       ?>
       	<?php if(comments_open()) : ?>
       		<div id="respond">
       			<h3 id="reply-title"><?php _e('Leave a Reply'); ?> <small><?php cancel_comment_reply_link(); ?></small></h3>
   
       			<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
       				<?php
       				if(get_option('comment_registration') && !$user_ID)
       				{
       				?>
       					<p>
       						<?php printf(__('You must be <a href="%1$s/wp-login.php?redirect_to=%2$s">logged in</a> to post a comment.'), get_option('siteurl'), urlencode(get_permalink())); ?>
       					</p>
       				<?php
       				} else {
       				?>
       					<?php if(!is_user_logged_in()) { ?>
       						<p class="comment-form-author">
       							<input type="text" name="author" class="data_author" value="<?php _e('Name', 'fazio'); ?>" data-defaultvalue="<?php _e('Name', 'fazio'); ?>">
       						</p>
   
       						<p class="comment-form-email">
       							<input type="text" name="email" class="data_email" value="<?php _e('Email', 'fazio'); ?>" data-defaultvalue="<?php _e('Email', 'fazio'); ?>">
       						</p>
   
       						<p class="comment-form-url">
       							<input type="text" name="url" class="data_url" value="<?php _e('Website', 'fazio'); ?>" data-defaultvalue="<?php _e('Website', 'fazio'); ?>">
       						</p>
       					<?php } ?>
       					<textarea name="comment" id="comment" class="data_comment"></textarea>
       					<?php comment_id_fields(); ?>
       					<input type="submit" name="submit" class="submit" value="<?php _e('Send comment', 'fazio'); ?>">
       				<?php
       				}
       				?>
       			</form>
       		</div><!-- end respond -->
       	<?php endif; ?>
       <?php endif; ?>
       ```
   
 * With:
 *     ```
       <?php if(!is_single()) : ?>
       	<a href="<?php the_permalink(); ?>">Leave a comment</a>
       <?php else : ?>
   
       	... the code ...
   
       <?php endif; ?>
       ```
   
 * This will show a “leave a comment” link when you are NOt viewing a single post.
 *  Thread Starter [giantman](https://wordpress.org/support/users/giantman/)
 * (@giantman)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754522)
 * Santiago,
 * Sorry to ask again but I have one last problem. I want to keep the “Leave a comment”
   link below the post, but I DON’T want to show the comments anymore. How can I
   do that?
 * I’ve tried removing the php if(!is_single()) and the else and endif but that 
   brought back the “Leave a reply” form.
 * I also tried removing the code from the home.php (The withcomments code) but 
   that removed the link AND the reply form.
 * I just want the “Leave a reply” link under each post without the reply form or
   the comments showing. How?
 *  [Santiago](https://wordpress.org/support/users/teleportz/)
 * (@teleportz)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754523)
 * In home.php, replace:
 *     ```
       <?php require('dry/post.php'); ?>
       					<?php
       						$withcomments = 1;
       						comments_template(FALSE, TRUE);
       					?>
       ```
   
 * To:
 *     ```
       <?php require('dry/post.php'); ?>
       <a href="<?php the_permalink(); ?>">Leave a comment</a>
       ```
   
 * Or something like that. You don’t need to include the comments template if you
   are not going to show the comments :p
 *  [Leve](https://wordpress.org/support/users/leve/)
 * (@leve)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754653)
 * Hi!
    I am using this code to show comments on my indexpage but this code outputs
   all the comments, i would love if the code could fetch the 3 latest comments 
   in a post, is this possible?
 * <?php
    global $withcomments; $withcomments = true; comments_template(); ?>

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Show comments code’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 14 replies
 * 5 participants
 * Last reply from: [Leve](https://wordpress.org/support/users/leve/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/show-comments-code/#post-1754653)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
