about semantic web, software architecture and life in general

Post details: b2evo: Last commented posts

2004-08-15

Permalink 23:32:39, Categories: b2evolution   English (EU)

b2evo: Last commented posts

Wrote code to display a box with last commented posts in b2evolution.

Simple, yet useful thing - displays a list of posts that have been commented last. Each post is displayed only once, a number after a post indicates how many comments it currently has.

[More:]

To add this feature, you will need to download code of _commentbox.php and place it in the blogs/skins directory.

In the _main.php of your skin (I used fplanque2002) add this code in the location where you want to see the comment box:

require get_path('skins').'/_commentbox.php';

Changes needed to _class_comment.php:

In class member variables list:
var $num_comm;

In the constructor Comment right after comment carma assignment:
$this->num_comm = $db_row['num_comm'];

To the constructor _class_commentlist.php:

In the constructor parameters list add 1 more parameter:

$init_what_to_show = '',
$group_by_post = false )        // group comments by post_ID and count the number of posts in num_comm

"improve" query:

if( $group_by_post )
   $this->request = "SELECT DISTINCT count(*) num_comm, comment_post_ID, max(comment_date) comment_date, ID, post_title ";
else $this->request = "SELECT DISTINCT $tablecomments.* ";

and add grouping instructions BEFORE the ORDER BY instructions:

if( $group_by_post )
   $this->request .= " GROUP BY $tablecomments.comment_post_ID ";

That is it. You may download resulting _class_commentlist.php.

However, there is one known bug I could not fix:

If you enter a blog different from default "All blogs", you may notice that a number of comments has doubled or tripled for some posts.

This happens if a post is filed in more than 1 category in the current blog.

It would be the best to just call some imaginary function get_comment_num() which returns the number of comments this post has. I played with generate_ctp_number(), but it did not work for me. If this is fixed, you would not need to modify _class_comment.php any more.

That'll be good if someone can fix this.

Comments, Pingbacks:

Comment from: captsolo [Member] Email
Re.: I played with generate_ctp_number(), but it did not work for me.

Correction - the function (from _functions_comments.php) is called generic_ctp_number(). But it still does not return the number of comments. :(

PermalinkPermalink 2004-08-16 @ 10:34
Comment from: Walter [Visitor] · http://waltercruz.com
I´m a litlle busy now, but i will try do adapct this to more commented posts (i think that is only modify the SQL)!
PermalinkPermalink 2004-08-19 @ 21:13
Comment from: EdB [Visitor] · http://wonderwinds.com
Wonderful! I have it in use at http://rgsapilots.org and will address the multiplier problem by not allowing cross-posting across categories. Hopefully the issue is fixable as I would like to be able to use this elsewhere.
PermalinkPermalink 2004-08-20 @ 06:56
Comment from: Brian [Visitor] · http://www.extinctionwatch.co.uk
Great idea! But are you still offering support for your features? I notice your blog has not been updated for a while.
PermalinkPermalink 2004-12-13 @ 23:00
Comment from: captsolo [Member] Email
Brian,

Yes I do support it.
The blog is being updated now as well.
So - everything's all right. :)

CaptSolo
PermalinkPermalink 2005-01-20 @ 01:49
Comment from: Emery Kelly [Visitor] · http://www.the-internet-directory.org
I appreciate this blog. Thank you
PermalinkPermalink 2006-12-28 @ 19:30

This post has 13 feedbacks awaiting moderation...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, a, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

captsolo weblog

See also:

February 2012
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        
Last comments

Search

Gallery

www.flickr.com
captsolo's items Go to captsolo's photostream

Misc

Syndicate this blog XML

powered by
b2evolution
Page served in 0.458 seconds

Valid XHTML 1.0! Valid CSS! Valid RSS! Valid Atom!