| View previous topic :: View next topic |
| Author |
Message |
MarcDK Hooked :)

Joined: 29 Mar 2005 Posts: 131
      votes: 1
|
Posted: Wed Dec 21, 2005 12:02 Post subject: List entries with most comments? |
|
|
| See subject: Is it possible to show up the 10 or 5 entries with the most comments? That would really be nice. =) |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Wed Dec 21, 2005 14:32 Post subject: |
|
|
That's a great idea. It can be done fairly easily with a plugin. I've got one started. I may move this thread to the plugin request forum if you don't mind. _________________ RTFM |
|
| Back to top |
|
 |
MarcDK Hooked :)

Joined: 29 Mar 2005 Posts: 131
      votes: 1
|
Posted: Wed Dec 21, 2005 16:56 Post subject: |
|
|
| Thanx a lot =) |
|
| Back to top |
|
 |
EdB /bb|[^b]{2}/
Joined: 05 Jan 2004 Posts: 7123
  votes: 90
|
Posted: Wed Dec 21, 2005 18:18 Post subject: |
|
|
Way back in the day there was a hack that did this. A plugin for the phoenix generation would be cool.
PS: moved this to plugins request. |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Wed Dec 21, 2005 18:25 Post subject: |
|
|
I've got something underway. I have a question, though. Here's the code I'm using:
| Code: |
$list = new ItemList($blog, array(), '', '', -1, '', array(),
'', 'DESC', 'comments', 30); |
I'm telling it to order by 'comments'. But is that looking at the number of comments for the post, or the comment status of the post (open, closed or disabled)? I was hoping for the former, but it appears to be the latter. If this doesn't work then will I have to build a query (more likely queries) from scratch to get all post ids for the blog, then count the number of comments that match their ids?
EdB, if you can find the old hack I'd like to take a look at it. _________________ RTFM |
|
| Back to top |
|
 |
EdB /bb|[^b]{2}/
Joined: 05 Jan 2004 Posts: 7123
  votes: 90
|
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Wed Dec 21, 2005 20:21 Post subject: |
|
|
Those threads are about showing recent comments. I want to show links to the posts that have the most number of comments. _________________ RTFM |
|
| Back to top |
|
 |
EdB /bb|[^b]{2}/
Joined: 05 Jan 2004 Posts: 7123
  votes: 90
|
Posted: Wed Dec 21, 2005 20:28 Post subject: |
|
|
The details always mess me up!
Most heavily commented would be a unique animal. A good one too! Drive traffic to that which your readers found interesting and you create this global warming type of situation, only a good global warming: not the bad one that ruins the earth and puts snow shovel salesmen out of business. |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Thu Dec 22, 2005 15:51 Post subject: |
|
|
I have this almost working. I had to cobble together a big, gnarly SQL query with joins and what not, but it does spit out the post titles and their comment counts. And you can limit it to the top x posts, where x is a number you enter with a plugin param. The default is 5. You can see it here:
http://www.brendoman.com/dev/blogs/index.php
Now I've got to figure out how to generate the permalink url from outside the Item class. There's also a bug for posts that appear on more than one blog. The comments seem to get counted for each blog sometimes.
Here's the meat of the code, for those of you keeping score at home (of for anyone who wants to help):
| Code: |
$sql = "SELECT DISTINCT post_ID , post_title ,
COUNT(post_ID ) AS count
FROM evo_comments , evo_posts
INNER JOIN evo_postcats ON post_ID = postcat_post_ID
INNER JOIN evo_categories ON postcat_cat_ID = cat_ID
WHERE evo_posts.post_ID = evo_comments.comment_post_ID
and (cat_blog_ID = ".$params['blog'].")
group by post_ID ORDER BY `count` DESC
LIMIT ".$params['limit'];
$results = $DB->get_results($sql);
for ($i = 0; $i < $params['limit']; $i++) {
if ($results[$i]->count == '') break;
echo $results[$i]->post_title;
echo ' ('.$results[$i]->count.')<br />';
}
|
If anyone wants, I can give you the full plugin file so you can play with it. _________________ RTFM |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Sat Dec 24, 2005 10:51 Post subject: |
|
|
Got it! It's working now, permalinks and all. Same link as above. I'll clean it up and make a post about it. Then I'll see about a backport to 0.9.1 (as a hack) if you're still using it, MarcDK _________________ RTFM |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Sat Dec 24, 2005 12:13 Post subject: |
|
|
Here's the backport for b2evolution 0.9.x. Grab the file below and paste that into your skin. You can edit the default params if you want. Not as pretty as a plugin, but it works.
http://www.brendoman.com/media...tshack.txt _________________ RTFM |
|
| Back to top |
|
 |
MarcDK Hooked :)

Joined: 29 Mar 2005 Posts: 131
      votes: 1
|
Posted: Sun Dec 25, 2005 15:08 Post subject: |
|
|
I'm sorry but it does not work correctly for me. The first item has 132 comments. In reality it only has 44. This means he multiplies it with 3.
Any idea?
UPDATE: it also multiplies the third place two times which means that the 35 comments are becoming 70.
UPDATE 2: Ok it seems that every item in this list generated by this script has wrong numbers. The last one is also multiplied with 3 and so is the 4th one. Ony the second one is correct showing 117 comments which is correct. =( |
|
| Back to top |
|
 |
personman SuperGuru

 Joined: 09 Feb 2005 Posts: 2178
  votes: 15
|
Posted: Mon Dec 26, 2005 17:16 Post subject: |
|
|
Hmm, do those posts appear on more than one blog? That's a known bug. Do they appear in more than one category? What about the one that works, is it just in one category? _________________ RTFM |
|
| Back to top |
|
 |
MarcDK Hooked :)

Joined: 29 Mar 2005 Posts: 131
      votes: 1
|
Posted: Mon Dec 26, 2005 18:03 Post subject: |
|
|
Yes, many of my articles appear in more than one category. =/
Can't we just count the categories of an article and divide the number through that? |
|
| Back to top |
|
 |
|