Recent Topics

1 Jan 06, 2005 01:14    

The idea is a sidebar blurt that lists posts that have comments. Make it list the post with the newest comment first. Make it do all blogs or just the current blog. Make it link to the post and to the most recent comment. Make it have class. Make it using booze for variable names. Make it by dropping this in your _main where it belongs

<div class="bSideItem">
<h3>Recently Commented</h3>
<?php require( dirname(__FILE__).'/_recentcomments.php' ); // RECENTLY COMMENTED POSTS INCLUDED HERE ?>

Make the next chunk be _recentcomments.php in your skins/skinname folder

/* Posts with comments are listed in order of most recently commented first.
 * Hm!
 * Another incredible hack by EdB @
 * b2evolution - {@link}
 * Released under GNU GPL License - {@link}
 * @copyright (c)2003-2004 by Francois PLANQUE - {@link}
 * @package evoskins
 * @subpackage your_skin_name
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );

# You can customize the following as you wish:
# maximum number of recentcomment entries to display:
$recentcomment_limit = 12;
# recentcomment global delimiters:
$recentcomment_main_start = '';
$recentcomment_main_end = '';
# recentcomment item delimiters:
$recentcomment_item_before = '<li>';
$recentcomment_item_after = "</li>\n";
# show posts from all blogs?
$recentcomment_allblogs = true;
# show number of comments?
$recentcomment_comment_count = true;
# recentcomment show number class:
$recentcomment_comment_count_class = 'dimmed';

// --- donate to open source projects before you go any further! --- //

$kentucky = 'N';
$sour_mash = 0;
if( $recentcomment_allblogs ) {
	$sql = "SELECT ID, post_title, comment_ID FROM $tableposts JOIN $tablecomments ON ( ID = comment_post_ID ) WHERE post_status = 'published' GROUP BY comment_ID DESC, comment_post_ID";
	} else {
	$sql = "SELECT ID, post_title, comment_ID, post_category, cat_blog_ID FROM $tableposts JOIN $tablecategories ON ( post_category = cat_ID) JOIN $tablecomments ON ( ID = comment_post_ID ) WHERE post_status = 'published' AND cat_blog_ID = $blog GROUP BY comment_ID DESC, comment_post_ID";
$results = $DB->get_results($sql);
echo $recentcomment_main_start;
if ($results) {
	foreach ($results as $result) {
		$bourbon = $result->ID;
		$bourbon_string = (string)$bourbon;
		$whiskey = strpos($kentucky, $bourbon_string);
		if( $whiskey === false ) {
			$kentucky = $kentucky.$bourbon_string.'N';
			$sour_mash = ($sour_mash+1);
			} else {
		if( $sour_mash > $recentcomment_limit ) {
		$query = "SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $bourbon";
		$count_comments = $DB->get_var($query);
		$post_title = stripslashes($result->post_title);
		$title = htmlspecialchars(stripslashes($result->post_title));
		$NewItem = Item_get_by_ID( $bourbon );
		$permalink = $NewItem->gen_permalink( '', '', false, '&' );
		$comment_link = $permalink.'#c'.$result->comment_ID;
		echo $recentcomment_item_before;
		echo '<a href="'.$permalink.'" title="link to '.$post_title.' post">'.$title.'</a>';
		if( $recentcomment_comment_count ) {
			$closing_bit = ' <span class="'.$recentcomment_comment_count_class.'">(<a href="';
			$closing_bit .= $comment_link.'" title="link to last comment on '.$post_title;
			$closing_bit .= ' post">'.$count_comments.'</a>)</span>';
			echo $closing_bit;
		echo $recentcomment_item_after;
	} else {
	echo $recentcomment_item_before;
	echo 'This sorry excuse for a blog ain\'t got no comments!';
	echo $recentcomment_item_after;
echo $recentcomment_main_end;


If you're bored and feel like clicking something [url=]follow this link[/url].

2 Feb 26, 2005 23:31

This worked really great when I was using B2Evo skins, but when I used it on WPC skins I kept getting parse errors. Members couldn't log in or out (if they were logged in from their last visit) either. I was using both this hack and the "recent posts" one. As soon as I took them both off, members were able to log in and log out again. I didn't have this problem AT ALL when I was using B2 skins. Anybody have any idea what happened there?

3 Feb 27, 2005 00:30

I'll try to look at this tomorrow for you. The thing is I do these hacks using skins that are all based on the custom skin. I've never actually used a WPC_* skin, so I can speak to any specific issue with them. My (sorry excuse for a) brain tells me a big feature with the WPC_* skins is that it is really easy for a WP skin to be moved into the b2evo world, but the disclaimer says some b2evo stuff ain't there. That doesn't help me understand why these hacks wouldn't work for you, and there's no way I can figure it out right now, but I'll try. Tomorrow.

4 Feb 28, 2005 00:54

Thanks EdB. Btw...I just discovered your modified Kubrick! Love it. :D

5 Mar 09, 2005 19:22

thanks for the hack, i just put it on mine.

i was thinking of doing it myself, but gave the forums a shot, and thank jeebus that you've already done it. thanks again.

6 Aug 08, 2006 12:56

I have updated this very nice hack (thanks EdB) to conform to 1.8 new function calls. AFAIK, only three lines of code have to be changed:

$bourbon = $result->ID;

was changed to:

$bourbon = $result->post_ID;


$NewItem = Item_get_by_ID( $bourbon );
$permalink = $NewItem->gen_permalink( '', '', false, '&' );

was changed to:

$NewItem = $ItemCache->get_by_ID( $bourbon );
$permalink = $NewItem->get_permanent_url( '', '', false, '&' );

That's it. Now it is working for me. I don't know how I could survive for more than week with out it.

7 Aug 08, 2006 16:05

I'm glad you liked it enough to upgrade it, and really glad you shared the results of your efforts with others who might want to use that hack!

(I remember when I wanted to write a hack using booze as variable names but didn't recall exactly what I used them on.)

8 Aug 27, 2006 01:24

Weird. When I try the updated script, I get a "please do not access this page directly" in the sidebar. Any thoughts on what it might be? I did a direct copy and paste on the script and updated it per Austriaco's script but no luck.

Also, is there a straight up "last comments" and "recently posted" plugin for 1.8 yet? I can't seem to find it if it exists.

Thanks for all the help!

9 Aug 27, 2006 02:01

You might have to change the following for 1.8..

if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' )


if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );

10 Aug 27, 2006 05:22

John - thanks.

That got me closer, but now I'm getting this error:

Additional information about this error:

MySQL error!

Unknown column 'ID' in 'field list'(Errno=1054)

Your query:

SELECT ID, post_title, comment_ID
FROM evo_posts JOIN evo_comments ON ( ID = comment_post_ID )
WHERE post_status = 'published'
GROUP BY comment_ID DESC, comment_post_ID

I'm hoping this is obvious to you b/c it's greek to me.

12 Aug 27, 2006 15:01

It is. All formerly working in 0.9.2, but I would expect them to stop working in 1.8. Thoughts on what it might be?

13 Aug 27, 2006 15:31

The solution for 1.8.1 is in that same post...
I'm using it at the moment...

14 Aug 28, 2006 04:06

Topanga - I got the includecomments.php to work - any idea on how to get recent comments to work? Another thing I'm trying to figure out is how to show the recent posts ... any thoughts on that?

Thanks for the great programming.

15 Aug 28, 2006 07:02

Elaborate me on the difference between
including the 5 latest comments in the sidebar
including the 5 recent comments in the sidebar...

for me the 5 latests are the 5 recent..

16 Aug 28, 2006 12:53

Ha - you have a point there. But I guess what I'd like to do is have Isaac's recent hack work for 1.8, which was my original intention. Then I stumbled on this hack which I figured I'd give a go. Now that I've got includecomments working, I'm back to my original intention - which is to get the recent hack going again.

18 Aug 28, 2006 15:31

Now I think I've just confused the issue.

Recentcomments and includecomments are essentially doing the same thing - like you pointed out. What I'd like to have is a recent posts - that just lists the last 10 posts on the site regardless of whether they've been commented on or not. This was done previously with _recent.php. You don't know how to fix this for 1.8.1 do you?

19 Aug 28, 2006 15:58


What I'd like to have is a recent posts - that just lists the last 10 posts on the site regardless of whether they've been commented on or not. This was done previously with _recent.php. You don't know how to fix this for 1.8.1 do you?

For the last 12 posts I simply use ...

<h3><?php echo T_('Recent posts') ?></h3>

		<?php	// Get the 12 last posts for each blog:
			$BlogBList = & new ItemList( $blog,  '', '', '', '', '', array(), '', 'DESC', '', 12, '', '', '', '', '', '', '', 'posts' );

			while( $Item = $BlogBList->get_item() )
			<li><a href="<?php $Item->permanent_url() ?>" rel="bookmark" title="<?php echo T_('Permanent link to ...') ?><?php $Item->title(); ?>"><?php $Item->title(); ?></a></li>

Change the number 12 to whatever you want
Works in 1.8.1

20 Aug 28, 2006 16:06

That worked great - Thanks John!

21 Aug 28, 2006 19:31

Neal.. that is exactly what I pointed you to too....
grrr ;)

Form is loading...