farfromfearless

How To Quote Comments In A WordPress Comment List

Sometimes it's the little details that make WordPress themes really shine, other times it's the little features you can add that make working with a WordPress theme a nice experience for readers.

I received an email from a reader this afternoon, asking about one of the commenting features that I built into the Lemon Twist theme: quote comments.

Hi Chris,

I’m really curious on how you got that quote feature on your comment section. Do you mind sharing your code?

Cheers,
[author name omitted]

While this is not a new feature by and large, it is one that I thought would bring a sense of discussion to the linear WordPress comment format much like how forums work. I’ve attempted to use threaded commenting plugins, but they are ugly and overly complicated for something that should be fairly straight forward.

In any case, this is the JavaScript snippet that I wrote (you need jQuery, but comes with the theme)

// attach a function to the quote comment link
  $('a.quote-comment').click( function() {
      var tb = $('#comment');
      var strQuote = $(this).attr('title');
      // assign the value
      tb.val('<blockquote>' + strQuote + '</blockquote>');
      return false;
   });

This is the result:

quote

There are a couple caveats to this feature

  1. You can only quote one comment at a time, as I didn’t build in concatenation.
  2. It is not parameterized so you’ll have to customize it for your own theme.
  3. Requires some additional styling (no big deal).

If anyone wants to improve on this, feel free to share!

  • (3) Comments
  • RSS 2.0
  • farfromfearless

3 people have left comments

Michael - Gravatar

Michael said:

Great stuff Chris, really appreciate your help.

Posted on: August 29, 2008 at 7:50 pmQuote this Comment
adie - Gravatar

adie said:

Hi Chris, actually i drop by here for your great twilight saga theme, thanks! that was a great job. But when i walked around found this useful tips, once again, thanks!

Posted on: August 31, 2008 at 9:59 amQuote this Comment
Josh Budde - Gravatar

Josh Budde said:

Nice! I’ve been looking for something like this for awhile.

Posted on: October 19, 2008 at 8:28 amQuote this Comment

Leave a Comment-

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs are automatically generated. Off-topic or inappropriate comments will be edited or deleted. Email addresses will never be published. Keep it PG-13 people!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

All fields marked with "*" are required.