View previous topic :: View next topic |
Author |
Message |
Cyberian75
Joined: 26 Sep 2002 Posts: 1095 Location: Oregon
|
Posted: Wed May 21, 2003 3:57 pm Post subject: [Hack] Top Commenters with Count |
|
|
You are welcome to improve on this draft hack. It's very ugly right now.
Code: |
<?php
//By Michael H. Park (http://www.MichaelPark.net)
function topcommentcount($commenter) {
global $tablecomments, $querycount;
$tccquery = "SELECT COUNT(comment_author) AS totalcount FROM $tablecomments WHERE comment_author = '$commenter'";
$tccresult = mysql_query($tccquery) or die(mysql_error());
$rowcount = mysql_fetch_object($tccresult);
$commentcount = $rowcount->totalcount;
$querycount++;
return($commentcount);
}
function topcommenters() {
global $tablecomments, $querycount;
$tcquery = "SELECT DISTINCT comment_author, comment_author_url " .
" FROM $tablecomments " .
" WHERE comment_content NOT LIKE '%<trackback />%' AND comment_content NOT LIKE '%<pingback />%' " .
" AND comment_content != ''" .
" ORDER BY comment_author";
$tcresult = mysql_query($tcquery) or die(mysql_error());
$querycount++;
while ($rows = mysql_fetch_array($tcresult)) {
$commentauthor = stripslashes($rows["comment_author"]);
$commentauthorurl = $rows["comment_author_url"];
$commentcount = topcommentcount($commentauthor);
if (empty($commentauthorurl) || strlen($commentauthorurl) < 12) {
echo $commentauthor.' ('.$commentcount.')<br>';
}
else {
echo '<a href="'.$commentauthorurl.'" target="_blank">'.$commentauthor.'</a>'.' ('.$commentcount.')<br>';
}
}
}
?>
|
_________________ Michael P. |
|
Back to top |
|
 |
epolady
Joined: 30 Jul 2002 Posts: 800 Location: Texas
|
Posted: Wed May 21, 2003 8:08 pm Post subject: |
|
|
Where does a php newbie such as myself put this code?  |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1095 Location: Oregon
|
Posted: Wed May 21, 2003 8:18 pm Post subject: |
|
|
I don't recommend using it until someone fixes it up.  _________________ Michael P. |
|
Back to top |
|
 |
Sydney
Joined: 11 Feb 2003 Posts: 20 Location: Netherlands
|
Posted: Thu Jun 26, 2003 9:42 am Post subject: |
|
|
Could someone fix it up??
*puppy dog eyes* _________________ Sydney |
|
Back to top |
|
 |
GooGirl
Joined: 15 Jul 2003 Posts: 19
|
Posted: Fri Aug 01, 2003 12:13 am Post subject: |
|
|
I like it as it is! Can I use it??
I uploaded it and all, but it's not ordering the comments from highest to lowest.. it's just listing all the commenters and the number of comments next to their name. What would I have to include in this to get it ordered?:
Code: | <?php topcommenters(); ?> |
Cool idea And thanks if you can help! _________________ "That which you do not risk leaves you risking so much more."
Always,
~GooGirl |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1095 Location: Oregon
|
Posted: Fri Aug 01, 2003 2:20 am Post subject: |
|
|
Try replacing the following:
Code: |
ORDER BY comment_author
|
With the following:
Code: |
ORDER BY comment_author DESC
|
_________________ Michael P. |
|
Back to top |
|
 |
Gadget Girl
Joined: 25 Jan 2002 Posts: 305 Location: Virginia
|
Posted: Fri Aug 01, 2003 11:19 pm Post subject: |
|
|
How do I pull this into the blog sidebar?
Code: | <?php topcommenters(); ?> | Isn't working.
Code: | <?php include ("/home/xxx/public_html/xxx/topcommenters.php"); ?> | Isn't working either, it's just blank. |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1095 Location: Oregon
|
Posted: Sat Aug 02, 2003 1:40 am Post subject: |
|
|
Where did you copy the code in? _________________ Michael P. |
|
Back to top |
|
 |
Gadget Girl
Joined: 25 Jan 2002 Posts: 305 Location: Virginia
|
Posted: Sat Aug 02, 2003 1:57 am Post subject: |
|
|
I just made it a php file. There wasn't any instructions as to what to do with it in this thread. |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1095 Location: Oregon
|
Posted: Sat Aug 02, 2003 4:37 pm Post subject: |
|
|
You have to include that file at the bottom of "b2template.functions.php" file right before "?>". _________________ Michael P. |
|
Back to top |
|
 |
Gadget Girl
Joined: 25 Jan 2002 Posts: 305 Location: Virginia
|
Posted: Sat Aug 02, 2003 7:09 pm Post subject: |
|
|
It's a great hack, now that I know where to put it and what to include where.
Code: | function add_filter($tag, $function_to_add) {
global $b2_filter;
if (isset($b2_filter[$tag])) {
$functions = $b2_filter[$tag];
if (is_array($functions)) {
foreach($functions as $function) {
$new_functions[] = $function;
}
} elseif (is_string($functions)) {
$new_functions[] = $functions;
}
/* this is commented out because it just makes PHP die silently
for no apparent reason
if (is_array($function_to_add)) {
foreach($function_to_add as $function) {
if (!in_array($function, $b2_filter[$tag])) {
$new_functions[] = $function;
}
}
} else */if (is_string($function_to_add)) {
if (!@in_array($function_to_add, $b2_filter[$tag])) {
$new_functions[] = $function_to_add;
}
}
$b2_filter[$tag] = $new_functions;
} else {
$b2_filter[$tag] = array($function_to_add);
}
return true;
}
function topcommentcount($commenter) {
global $tablecomments, $querycount;
$tccquery = "SELECT COUNT(comment_author) AS totalcount FROM $tablecomments WHERE comment_author = '$commenter'";
$tccresult = mysql_query($tccquery) or die(mysql_error());
$rowcount = mysql_fetch_object($tccresult);
$commentcount = $rowcount->totalcount;
$querycount++;
return($commentcount);
}
function topcommenters() {
global $tablecomments, $querycount;
$tcquery = "SELECT DISTINCT comment_author, comment_author_url " .
" FROM $tablecomments " .
" WHERE comment_content NOT LIKE '%<trackback />%' AND comment_content NOT LIKE '%<pingback />%' " .
" AND comment_content != ''" .
" ORDER BY comment_author";
$tcresult = mysql_query($tcquery) or die(mysql_error());
$querycount++;
while ($rows = mysql_fetch_array($tcresult)) {
$commentauthor = stripslashes($rows["comment_author"]);
$commentauthorurl = $rows["comment_author_url"];
$commentcount = topcommentcount($commentauthor);
if (empty($commentauthorurl) || strlen($commentauthorurl) < 12) {
echo $commentauthor.' ('.$commentcount.')<br>';
}
else {
echo '<a href="'.$commentauthorurl.'" target="_blank">'.$commentauthor.'</a>'.' ('.$commentcount.')<br>';
}
}
} |
Put the above code as is, in the b2template.functions.php right before the end ?>
Then, put Code: | <?php topcommenters(); ?> | in your sidebar to pull it into your blog and show the commenters tally.
Sara |
|
Back to top |
|
 |
Gadget Girl
Joined: 25 Jan 2002 Posts: 305 Location: Virginia
|
Posted: Sat Aug 02, 2003 7:14 pm Post subject: |
|
|
Now that it's working, any clues as to show say the top 10 commenters only? Right now it's showing all the commenters alphabetically. |
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1095 Location: Oregon
|
Posted: Sat Aug 02, 2003 8:26 pm Post subject: |
|
|
My intention was to list them from the highest number of comments. Apparently, though, it doesn't work as intended.
Anyway, to limit the number, put "limit 10" at the end of the SQL query in the second function. _________________ Michael P. |
|
Back to top |
|
 |
patrick
Joined: 22 Jul 2003 Posts: 4 Location: new jersey
|
Posted: Sat Aug 02, 2003 10:17 pm Post subject: |
|
|
erm... stupid question but what exactly does it do? _________________ o.O___patrick |
|
Back to top |
|
 |
Gadget Girl
Joined: 25 Jan 2002 Posts: 305 Location: Virginia
|
Posted: Sat Aug 02, 2003 10:18 pm Post subject: |
|
|
Thanks for the help Michael, but I have tried putting limit 10 everywhere and there is an error. Where exactly should it go? Please paste the line and where to find it and add the code as well, thanks.
 |
|
Back to top |
|
 |
|