Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Customize Comment Reply Link WordPress

  • SOLVED

Hello!
I want to modify the Comment Reply Link to use a lightbox effect for replies. I have the lightbox part working fine, as you can see on the demo site (http://themes.mikemcalister.com/wp/FreshStart/?p=346). Click "Reply to this Comment" to see the effect.




function my_replylink($c='',$post=null) {
global $comment;
// bypass
if (!comments_open() || $comment->comment_type == "trackback" || $comment->comment_type == "pingback") return $c;
// patch
$id = $comment->comment_ID;
$reply = 'Reply to this Comment';
$o = '<a class="comment-reply-link" rel="prettyPhoto" id="'.$id.'" href="'.get_permalink().'?replytocom='.$id.'#respond">'.$reply.'</a>';
return $o;
}
add_filter('comment_reply_link', 'my_replylink');



This code brings up the reply form in the lighbox as it should, but the reply doesn't work. It just adds the comment as a regular comment, not a threaded one.


$o = '<a class="comment-reply-link" rel="prettyPhoto" id="'.$id.'" href="#respond">'.$reply.'</a>';


Any help is appreciated, thanks folks!

Answers (3)

2011-01-25

Oleg Butuzov answers:

Threaded comments works in a bit different way.

1) You should provide a way to show tham
2) A bit customize a replay form.

2011-01-25

John Cotton answers:

You have a hidden field element in the pop up form call "comment_parent"
which is set to 0. It should be the id of the comment clicked...

I guess that's because you're just taking the form html from the bottom of the page (I only had a quick look and I couldn't find quite how you were doing it).

So you need to add some code - a little bit of jQuery to react to the click (rather than relying on the rel="prettyPhoto" which I think you are now) and then set the form value from the id you've got stored in each link, and <em>then</em> show the lightbox...

JC

2011-01-25

Ivaylo Draganov answers:

There's a hidden input field in the comment form called "comment_parent". By default it has a value of "0":
<input type="hidden" value="0" id="comment_parent" name="comment_parent">

You have to change this value to the ID of the comment which is being replied to. Wordpress uses javascript to handle that (and also moving the comment form, but you obviously don't need that). You can try to extract what you need from <em>wp-includes/js/comment-reply.js</em> and apply it to your form.


Mike McAlister comments:

Would you be willing/able to make this change if I make this into a job instead and added more prize money?


Ivaylo Draganov comments:

I am not good with JavaScript. I think it should be something along the lines of:

// select comment reply link
J(".comment-reply-link")
// trigger event on mouse click
.click(function() {
// get id of the link(and also parent comment)
var parent = J(this).attr("id");
// set the value of input#comment_parent
J("#comment_parent").attr("value", parent);
})
// attach lightbox to it
.prettyPhoto({theme: 'light_square'})



I've not tested that. Try and see what you get. And you can remove the <em>rel</em> attribute from comment links and use their classes instead.