0

WordPress usually has "Leave a Comment, "1 Comment," or "% Comments" on the blog page, and I want people to be able to hover over that and have jQuery show the latest comment in a rectangular box below it (pushing down all subsequent content). Obviously they'd click through to read more comments or respond, but I can't figure out where to start and go from there.

As an example, if you look at the site Destructoid, they show the latest comment after each post. I want to show something similar, but only after the "# comments" is hovered over. Only then would the box with the latest comment show up and push the rest of the content down. It would disappear if the mouse is moved off of the link or box itself.

I figure get_comments can be used to call it, but comments_popup_link doesn't take arguments for alt text or jQuery boxes, I don't think. Any suggestions?

1

The comments_popup_link_attributes filter will allow you to output attributes within the link.

function add_comment_hover_action() {
  echo ' onHover="fireMyJSCode();"';
}
add_filter(‘comments_popup_link_attributes’, ‘add_comment_hover_action’);

Alternately, you could hook into the comments_number filter to add a span wrapper around the comment number text with a common class name and the parent post id as an attribute. Then in JavaScript you could assign a function to handle hover actions for all those comment spans. Inside your js function hover handler access the post id from the wrapper element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.