A nicer Looking Comments Plugin?

Feed 7 posts, 4 voices

Avatar
3 posts

Is there a way to make the comments section look a little bit nicer? I would kind of like to have the comment form hidden unless a user clicks an “add comment” link then have it drop down. I’m thinking either mootools or jquery is the way to do this but I cant quite wrap my head around how to implement it. Any help would be greatly appreciated!

Thanks!

 
Avatar
343 posts

You can try this, not tested :) but should work.
Go to Snippets and look for comment-form , click on it so the editor comes up. This is what you should find :

<form action="<?php echo $this->url(); ?>" method="post" id="comment_form"> 
<p>
	<input class="comment-form-name" type="text" name="comment[author_name]" id="comment_form_name" value="" size="22" /> 
	<label for="comment_form_name"> name (require)</label>
</p>
<p>
	<input class="comment-form-email" type="text" name="comment[author_email]" id="comment_form_email" value="" size="22" /> 
	<label for="comment_form_email"> email (will not be published) (required)</label>
</p>
<p>
	<input class="comment-form-link" type="text" name="comment[author_link]" id="comment_form_link" value="" size="22" /> 
	<label for="comment_form_link"> website</label>
</p>
<p>
	<?php captcha(); ?>
</p>
<p>
	<textarea class="comment-form-body" id="comment_form_body" name="comment[body]" cols="100%" rows="10"></textarea>
</p>
<p>
	<input class="comment-form-submit" type="submit" name="commit-comment" id="comment_form_submit" value="Submit comment" />
</p>
</form>

The first step is to get the jQuery (my choice) library. Here’s a online hosted one :

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

Now you have to write the hide/show code for your comment form.

<script type="text/javascript">
	//<![CDATA[
		$(function() {
			$("#comment_form").hide();
			$("#add_comment").click(function() {
				$("#comment_form").animate({ opacity: 'toggle' });
			});
		});
	//]]>
</script>

The thing is I hide the comment form through javascript, so if a user has JS disabled, he will see the form. If you will hide it from css with display:none and JS is off, the user is unable to use the form. You get the idea.

Now we have to add a button to display the form on click event. It has to match the id : #add_comment ( if you need another id please replace it in the JS provided ).

<a href="#comment_form" id="add_comment" title="Add a new comment">Add comment</a>

And here is the full code, at last :

<a href="#comment_form" id="add_comment" title="Add a new comment">Add comment</a>
<form action="<?php echo $this->url(); ?>" method="post" id="comment_form"> 
<p>
	<input class="comment-form-name" type="text" name="comment[author_name]" id="comment_form_name" value="" size="22" /> 
	<label for="comment_form_name"> name (require)</label>
</p>
<p>
	<input class="comment-form-email" type="text" name="comment[author_email]" id="comment_form_email" value="" size="22" /> 
	<label for="comment_form_email"> email (will not be published) (required)</label>
</p>
<p>
	<input class="comment-form-link" type="text" name="comment[author_link]" id="comment_form_link" value="" size="22" /> 
	<label for="comment_form_link"> website</label>
</p>
<p>
	<?php captcha(); ?>
</p>
<p>
	<textarea class="comment-form-body" id="comment_form_body" name="comment[body]" cols="100%" rows="10"></textarea>
</p>
<p>
	<input class="comment-form-submit" type="submit" name="commit-comment" id="comment_form_submit" value="Submit comment" />
</p>
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
	//<![CDATA[
		$(function() {
			$("#comment_form").hide();
			$("#add_comment").click(function() {
				$("#comment_form").animate({ opacity: 'toggle' });
			});
		});
	//]]>
</script>

I hope this helps, have a nice day.

 
Avatar
343 posts

Sorry for the double post, but it seems there is a bug with this forum, it cuts my post.
If you want to modify the effect on hide/show you can modify this line :

$("#comment_form").animate({ opacity: 'toggle' });

With:

Accordion effect :

$("#comment_form").animate({ height: 'toggle' }); 

No effect :

$("#comment_form").toggle();

You can do much more flashy things but you will need the easying plugin or jQuery UI. Have fun |:)

 
Avatar
3 posts

Wow that is awesome! Thank you so much I will give this a shot tomorrow!

 
Avatar
343 posts

No problem. Hope it works.

 
Avatar
10 posts

any working result? :)

 
Avatar
48 posts

Here is a working example. Browse little bit around.

 
Avatar
343 posts

That’s what the script above does.