Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

2 different comment templates for one WP site?

Featured Replies

Hey all,

 

I hope you are well.

 

I'm busy with a site and I need to have 2 different types of comments forms. The usual comments on posts is pretty much sorted out.

 

However, I want to call a different comment template for pages.

 

 

Right now the default call from the template page is:

<?php comments_template(); ?>

 

That function calls to the comments.php file.

 

 

However I want to call comments2.php which is my other comments page template.

I have tried:

<?php include('comments2.php'); ?>

 

It does work but doesn't show the comments, just the comment form.

 

I have a feeling a need to tweak some of the code in the actual comments2.php file. As I know pretty much next to nothing about this level of php, I don't know where to start.

Here is the code that isn't display:

<?php // Do not delete these lines
if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
	die ('Please do not load this page directly. Thanks!');

       if (!empty($post->post_password)) { // if there's a password
           if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
			?>

			<p class="nocomments">This post is password protected. Enter the password to view comments.<p>

			<?php
			return;
           }
       }

	/* This variable is for alternating comment background */
	$oddcomment = 'alt';
?>

<!-- You can start editing here. -->

<?php if ($comments) : ?>
<h3 id="comments"><?php comments_number('No comments', 'One Response', '% Responses' );?>, be sure to add yours.</h3> 

<ol class="commentlist">

<?php foreach ($comments as $comment) : ?>

	<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">
		<cite><?php comment_author_link() ?></cite> Says:
		<?php if ($comment->comment_approved == '0') : ?>
		<em>Your comment is awaiting moderation.</em>
		<?php endif; ?>
		<br />

		<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('e','',''); ?></small>

		<?php comment_text() ?>

	</li>

<?php /* Changes every other comment to a different class */	
	if ('alt' == $oddcomment) $oddcomment = '';
	else $oddcomment = 'alt';
?>

<?php endforeach; /* end for each comment */ ?>

</ol>

<?php else : // this is displayed if there are no comments so far ?>

 <?php if ('open' == $post->comment_status) : ?> 
	<!-- If comments are open, but there are no comments. -->

 <?php else : // comments are closed ?>
	<!-- If comments are closed. -->
	<p class="nocomments">Comments are closed.</p>

<?php endif; ?>
<?php endif; ?>

 

Any suggestions or even a fix would be appreciated.

Thanks!

<?php if(is_page()) { include('comments-2.php'); } ?>

 

Does that work?

 

Have you tried using comments-2.php instead of comments.php for your posts? Does that work? Does the form on both comments pages have the same action?

Just had a thought.

 

You could always try the is_single() / is_page() aspect in comments.php.

 

How different are the two comments files?

  • Author

Thanks Rachael, if give those a bash - was thinking of implementing the is_ tags.

 

Will give feedback soon.

 

 

The two files aren't too different, same function, just different copy basically.

Yea, the way I would do that is all within the comments.php file itself the way that rachael has mentioned

Its very easy, you use comments-2 in the css if I recall, well thats what I do on mine also got one for admin.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.