Forums

Most commented items

kundu 19 Oct, 2008
Hello.

This extension is fantastic! Thank you!
But is there any way to show the most commented articles? thanks
Max_admin 19 Oct, 2008
Hi kundu,

there is no way available currently to do this but it can be made of course, the key will be the SQL statement to find the articles with most comments, you may hack the comments module, we can work through this code together here if you like.

Cheers,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kundu 22 Oct, 2008
hhmm...i'm newbie, but i already now how to do it. i'll post it later, when I have time. Thanks for the tip. 'twas very usefull!!

Kundu
kundu 04 Nov, 2008
Ok. I guess we can start. First of all, sorry for my english. I'm a portuguese native speaker. As I said before I'm not a joomla professional. I've started in september.

... the key will be the SQL statement to find the articles with most comments, you may hack the comments module, we can work through this code together here if you like.



So, I went to the comments module and where we have:
$query = "SELECT a.*, b.title AS articletitle FROM #__chrono_comments AS a, #__content AS b WHERE a.pageid = b.id AND a.published='1' AND a.verify='1'".$extra." ORDER BY a.datetime ".$params->get( 'order', 'ASC' )." LIMIT 0,".$params->get( 'commentscount', 5 );
		$database->setQuery( $query );

I did several things. Like, i cutted
$params->get( 'commentscount', 5 );
and pasted just bellow like this

$database =& JFactory::getDBO();
$commentscount	=	intval($params->get( 'commentscount', 5 ));



than just cutted the entirely code
$query = "SELECT a.*, b.title AS articletitle FROM #__chrono_comments AS a, #__content AS b WHERE a.pageid = b.id AND a.published='1' AND a.verify='1'".$extra." ORDER BY a.datetime ".$params->get( 'order', 'ASC' )." LIMIT 0,".$params->get( 'commentscount', 5 );
		$database->setQuery( $query );


and replace it by

$query = "SELECT count(a.id) AS most, a.id, a.pageid, b.id AS artid, b.title AS articletitle, b.sectionid AS id_section, b.catid AS id_categorie"
			. "\n FROM #__chrono_comments AS a, #__content AS b"
			. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = b.id"
			. "\n INNER JOIN #__categories AS cc ON cc.id = b.catid"
			. "\n INNER JOIN #__sections AS s ON s.id = b.sectionid"
			. "\n WHERE ( b.state = 1 AND b.sectionid > 0 )"
			. "\n AND (b.id = a.pageid AND a.published='1')"
			. "\n GROUP BY articletitle"
			. "\n ORDER BY most DESC";
		$database->setQuery( $query,0,$commentscount );


Sorry the oraganization here, i don't use to post things on forums. I don't know if this is the correct way of doing it, but it worked for me. Of course still things to do, like the output thing, etc...
Max_admin 04 Nov, 2008
great, thanks for sharing this!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
kundu 04 Nov, 2008
thanks for the component.
This topic is locked and no more replies can be posted.