How to show Comments on Slides only

Brian asked a few days ago:
I would like to only allow comments on the individual photos themselves, not the gallery or folders. Is there a way to do this?
You have two ways to make this work:

  1. By editing your comments_template
  2. By adding a filter to close comments

It all revolves around a small piece of code to check what is currently showing in your gallery:

global $lg_gallery;
if ($lg_gallery->is_gallery() && (!$lg_gallery->is_image($lg_gallery->file))) {
  // is this your gallery page and not a slide view? take action.
}

1. Changing you comments template

If you have adapted your comments template to work with Lazyest Gallery, in your comments template just below the line:

// You can start editing here -- including this comment! 

add the following code:

<?php global $lg_gallery; ?>
<?php
  if ($lg_gallery->is_gallery() && (!$lg_gallery->is_image($lg_gallery->file))) :
?>
</div>
 
<?php return; endif; ?>

This code will block displaying the comments form.

2. Close comments on Gallery and Folders

The comments_open filter is another way of controlling comments. Add the following code to your theme functions.php to close comments on the Gallery main page and folders:

function my_image_comments_open( $open ) {
	global $lg_gallery;
	if ( $lg_gallery->is_gallery() ) {
		if ( ! $lg_gallery->is_image( $lg_gallery->file ) )
			return false;
	}
	return $open;
}
add_filter( 'comments_open', 'my_image_comments_open' );

This code will also block displaying the comments form but in most themes the message Comments closed will appear on your page. This could confuse your visitors thinking they cannot add comments to images.
If you want to test for folders use $lg_gallery->is_folder( $lg_gallery->file )