Mark Comments by Current User

To highlight comments of the currenly logged-in user, add this plugin:

<?php
/*
Plugin Name: Comment Class for Logged-In User
Plugin URI: n/a
Description: add the comment_class .comment-author-logged-in for the comments of logged-in users.
Version: 1.0
Author: alchymyth
Author URI: http://transformationpowertools.com
License: GPL2
*/

add_filter( 'comment_class', 'comment_class_logged_in_user' );

function comment_class_logged_in_user( $classes ) {
	global $comment;
	if ( $comment->user_id > 0 && is_user_logged_in() ) {  
		global $current_user; get_currentuserinfo(); 
		$logged_in_user = $current_user->ID;  
		if( $comment->user_id == $logged_in_user ) $classes[] = 'comment-author-logged-in';
	}
return $classes;
}

//  requires formatting of the css class: 
//  .comment-author-logged-in { }
?>

Add a file with the above code into the /wp-content/plugins folder; activate the plugin under ‘appearance – plugins – installed plugins’; and add a corresponding style to the stylesheet of the currently used theme.

The code compares the comment author’s ID with the ID of the logged-in user, and adds the class .comment-author-logged-in to the ‘comment_class’ output.

Comments on the ‘Posts Page’ in WordPress

If you are using a static home page and have set one of your other pages to be the ‘posts page‘ [Codex], then there is no direct way to allow comments on that page.

You will need to do some custom programming to allow viewers to comment on the ‘posts page‘, i.e. not just on the individual posts, but on the whole page in general.

WordPress does not use any page templates for the ‘posts page‘, but uses index.php or home.php of the currently active theme – see template hierarchy.

This example assumes that the theme does not have a home.php, so we are doing the coding in index.php.

First, we need to check that we are on the ‘posts page‘, and that is set under dashboard – settings – reading:

if( is_home() && get_option('page_for_posts') ) :

Then we get the ‘original’ page using WP_Query():

$posts_page = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => 1, 'post__in' => array(get_option('page_for_posts')) ) );

We could then for instance output the content of that page as it is written in the page editor; this content would otherwise not get shown for a ‘posts page’; or use ‘get_template_part(‘content’,’page’)’ as in the example for Twenty Twelve.

Last we output the comments and comment form with:

global $withcomments; $withcomments = 1;
comments_template();
$withcomments = 0; 

The $withcomments = 1;  is needed to show the comments part in a ‘posts page‘.

The full example code is:

<?php if( is_home() && get_option('page_for_posts') ) :
$posts_page = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => 1, 'post__in' => array(get_option('page_for_posts')) ) );
if( $posts_page->have_posts() ) while( $posts_page->have_posts() ) : $posts_page->the_post();
get_template_part('content','page');
//this is for Twenty Twelve; or whatever you want to output from the 'posts page'
global $withcomments; $withcomments = 1;
comments_template();
$withcomments = 0;
endwhile; wp_reset_postdata();
endif; ?>