Alternating comment backgrounds with AJAX Comments.
-
I have been installing AJAX Comments and I love it, but it doesn’t support stylesheets that have alternating backgrounds (like the WordPress default!) in real-time (they’ll be fine after a refresh).
As such, I decided to hack in the functionality myself. Unfortunately, I’ve run into a small problem when it comes to understanding exactly what WordPress does with the comments array. Currently, AJAX Comments gets each new comment’s formating by requesting a new comment page with one comment (the latest) from comments.php. It then uses preg_match() to find the LI element and strip out the insides (class info and everything between the opening and closing tags).
To make alternating work, I need to have WordPress create a comments page with two comments rather than one, and then strip out the class info from the second one. Unfortunately, when I do so the second comment always seems to be blank. Every other comment will update properly in wonderful AJAX style, but the ones in between (requiring a comment file with two comments) are blank until a refresh.
Here’s the code I added to ajax-comments.php:
if($commentcount%2 == 0) $comments = array($comment, $comment);
and:
preg_match_all('#<li(.*?)>(.*)#ims', $commentout, $matches, PREG_SET_ORDER);
and:
if($commentcount%2 == 0) echo '<li '.$matches[1][1].' style="display:none">'.$matches[1][2].'';
Using preg_match_all() instead of preg_match() should get all the instances of the LI element instead of just one…but it doesn’t. I suspect that the problem occurs in the first line I added, and maybe WordPress won’t create a comment page with two of the same comment?
- The topic ‘Alternating comment backgrounds with AJAX Comments.’ is closed to new replies.