accessories-text-editor

Adapt the Lazyest Gallery comment template

The reason why I chose WordPress long ago, was the use of pluggable functions and hooks for actions and filters. Lazyest Gallery 1.1.x has its own pluggable functions and hooks. This article explains how to use these functions to adapt the Lazyest Gallery comment template to your theme.

If you can't adapt your theme's comments template, try adapting the Lazyest Gallery comment template.

Although the comment template is compatible with the Twenty Ten and Twenty Eleven, chances are, the comment template does not fit your theme.

The comment Template

For adapting the template, you need to have access to edit your (child) theme functions.php file, and some basic knowledge of the PHP scripting language
First, let's analyze what's in the comment template. It start with a lot of statements to check access to comments. The actual template starts below the line:

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

Reading this, you might feel tempted to edit the template to fit your needs. Please don't. You don't have to and your edits will be overwritten when you update Lazyest Gallery. We are going to use the pluggable functions.

Displaying comments

The comments for the Gallery are displayed in a loop, by calling wp_list_comments().

wp_list_comments( array( 'callback' => 'lazyest_comment' ) );

You see the callback is 'lazyest_comment'. This is the pluggable function we need to override.
Now, open your theme comments-template. Usualy this is the comments.php file.
Search for the wp_list_comments() statement. In my theme, it is:

<?php wp_list_comments('callback=ttrust_comments'); ?>

ttrust_comments is the function that displays a single comment, and is the function we need in our gallery comment template.

Override lazyest_comment

In this example, we use the ttrust_comments function. Replace this for your comment function.
Now, open your functions.php and add the following code:

function lazyest_comment( $comment, $args, $depth ) {
  ttrust_comments($comment, $args, $depth);
}

Save your functions.php and the Lazyest Gallery comment template will now show your theme's markup for comments.

The comment from

Right down at the bottom of the comments template is a call to lg_comment_form() show the comment input from. To override this, we need some more coding. First, we have to search for the comment form in our theme. It could be a separate function, it could also be part of the comment template in comments.php. In the Twenty Ten template, the default WordPress comment_form() is used.
Now, the tricky pert, we have to copy the whole function ad put it in our functions.php. If the comment from in comments.php is not a separate function, we need to wrap in into a function. Above the code put:

function lg_comment_form() {
  global $post, $user_identity, $comment_author, $comment_author_email, $comment_author_url;
  get_currentuserinfo();
  get_comment_author();
 

Below the code put:
}
If you have copied the compete function, rename the function name to lg_comment_form, and leave the rest, including parameters as-is.
The last thing to do is adding some code to link the comment to your images and folders.
Search in the comment form code for:

<?php comment_id_fields(); ?>

On a new line below this statement, put the code:

<?php lg_comment_id_fields(); ?>

Save your functions.php and now you have adapted the Lazyest Gallery comments template to your theme.

Be aware that not all themes have comment templates like this. Especially themes using ajax comments could have a different setup.
Overall, I think the Lazyest Gallery comment template can be adapted to most of the themes. Even the WPTouch comments could work under Lazyest Gallery, as you can see when you visit this site on your smartphone.

Have fun! Please your drop questions in the Forums

One thought on “Adapt the Lazyest Gallery comment template

  1. Pingback: Adapt your comments template to Lazyest Gallery | | Brimosoft | Brimosoft

Comments are closed.