For my site I added a block that mixes together last topics and last comments in desc order. I think that something similar should be included in advanced forum. What do you think?

Here is the code of my custom block (obviously, it can be further enhanced):

$allmessages=array();
$query_node=db_query("SELECT node.*, users.name FROM node LEFT JOIN users ON node.uid=users.uid WHERE (node.type='forum') ORDER BY node.created DESC LIMIT 5");
while ($node_array=db_fetch_array($query_node))
	{$message=array();
	$message["title"]=$node_array["title"];
	$message["link"]="http://www.mysite.com/node/".$node_array["nid"];
	$message["author"]=$node_array["name"];
	$message["timestamp"]=$node_array["created"];
	$allmessages[]=$message;
	}

$query_comments=db_query("SELECT comments.*, users.name AS uname, node.type FROM (comments LEFT JOIN users ON comments.uid=users.uid) LEFT JOIN node ON comments.nid = node.nid WHERE (node.type='forum') ORDER BY comments.timestamp DESC LIMIT 5");
while ($node_array=db_fetch_array($query_comments))
	{$query_page=db_query("SELECT COUNT(cid) as number FROM comments WHERE (nid = '$node_array[nid]') AND (timestamp<=$node_array[timestamp])");
	$num_array=db_fetch_array($query_page);
	$numpage=ceil($num_array["number"]/10);
	$message["title"]=$node_array["subject"];
	$message["link"]="http://www.mysite.com/node/".$node_array["nid"]."?page=$numpage#comment-".$node_array["cid"];
	$message["author"]=$node_array["uname"];
	$message["timestamp"]=$node_array["timestamp"];
	$allmessages[]=$message;
	}

$timestamp=array();
foreach ($allmessages AS $key => $message)
{$timestamp[$key]=$message["timestamp"];}

array_multisort($timestamp, SORT_DESC, $allmessages);

$output="<ul>";
$i=0;
foreach ($allmessages AS $key => $message)
{$output.='<li><a href="'.$message["link"].'">'.$message["title"].'</a><br />';
$output.='by <em>'.$message["author"]."</em><br />";
$output.=date("d/m/y - H.i", $message[timestamp]);
$output.="</li>";
if ($i>=4) break;
$i++;
}
$output.="</ul>";
print $output;

Comments

michelle’s picture

Version: 6.x-1.0-rc4 » 6.x-2.x-dev

I've been hoping to find a way to do this with views but didn't have much luck the last time I tried. With the switchover to nodecomments, this becomes a lot easier, but I'll keep this code around for the folks who stay on comments. Thanks. :)

Michelle

asxnot’s picture

I didn't know nodecomments module. That's interesting!!!
It can be a solution that simplifies a lot the management of forum. Just to make a better choice: are you planning to include the nodecomments module in the set of required modules in future versions of advanced_forum?

michelle’s picture

@asxnot: It won't be required but there will likely be some features that aren't available if you choose not to use it.

Michelle

michelle’s picture

Status: Active » Closed (won't fix)

I think we're starting to get Views overload with all the various views. For the majority of sites, this block isn't terribly useful since most sites don't use individual topics in forum reply posts. Those sites that need it can use a view (with nodecomments) or the code above. I've decided I'm not going to add it to AF.

Michelle

pinky.evakoss’s picture

Does advanced forum module work with nodecomment module ? I find several post in the issue list where people are using nodecomment module, but when I tried it I was unable to use nodecomment with advanced forum module because advanced_forum module is dependent on comment core module and node comment module works only if comment core module is disabled.

I need a similar block for posts and comments but i got no luck with views. Do I need to make it custom only?

Pinky

michelle’s picture

@pinky.cms: You're using the wrong version of Nodecomment. Use 2.x.

Michelle

Fogg’s picture

Hi folks,

guess I am a bit stupid right now. But what do I do with the code above? Where to place it and how to activate it? I tried to create a new block and put the code into the content - obviously did not work.

Thanks for your help!

CU Fogg

weka’s picture

Hi Fogg,

You did it correctly, just make sure you use PHP as the input format.
I just tried the code in AF 6.x2.0-alpha2 and it works.