The Plug Plugin
Thursday, March 22nd, 2007

Quick update, I installed a new plugin that spits out a list of people who commented on a post and links their name back to their respective websites. It’s a comment-whoring move to let others plug their sites on yours, but oh well, seeing as how most of the traffic into my site comes in that form anyway.

If you want to do the same thing (see the “complements of” after each post on the index page?), you can download it from that site.

I made a few quick changes to the code, though. I wanted commas in-between each person, so I needed to have the script put in a comma after every entry other than the last one. In order to do so, after the script files all comment authors and URLs into the array $commenters, I assigned a new variable $count the integer one and got a count of the array. In code form:

$result = count($commenters);
$count = 1;

(Hint: $count starts at 1 to account for the fact that I don’t want a comma after the last commenter) After that, I concatenated a comma onto the string after each commenter and added one to the count, other than the last one, by adding the following line:

if ($result!=$count) { $output .= ', '; $count++; }

All together, my version of the script, starting at the if ($commenters) line looks something like this (with various other little edits, for example, I took out the < li > and < ul > tags, but you get the general idea):

if ($commenters) {
  $output = '';
  $output2 = 'anonymous';
  $commenters = array_reverse($commenters);
  $result = count($commenters);
  $count = 1;

  print "
"; print ""; print "Complements of"; print "   "; foreach ($commenters as $commenter) { if (!empty($commenter->comment_author)) { if (!empty($commenter->comment_author_url)) { $output .= '' . $commenter->comment_author . ''; if ($result!=$count) { $output .= ', '; $count++; } } else { $output .= $commenter->comment_author . ''; if ($result!=$count) { $output .= ', '; $count++; } } } else $output .= $output2; } echo $output; print "
"; } } ?>

Isn’t coding fun?!


This entry was posted on Thursday, March 22nd, 2007 at 3:27 am and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed.

Tags: ,


Metadata

Filed under: Uncategorized

Tags: ,

Commentary

This post has one response.


  1. you lost me at “I installed…”

    Comment by Jane — March 28, 2007 @ 1:00 am

Leave a Reply


Comment

*


* Will not be published