how to show the last comments?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
presura
Forum Members
Forum Members
Posts: 20
Joined: Wed May 23, 2007 5:36 pm

how to show the last comments?

Post by presura »

Hi all,
I have a CMS made simple at www.stiinta.info.
Every news article accepts comments. I would like however now to show the last comments (from all news) on the main page...
Anybody can help me with some advice? I also installed RSS2HTML in case one cam make a feed out of the last comments...
thanks in advance,
cristian
scooper
Forum Members
Forum Members
Posts: 242
Joined: Fri Dec 09, 2005 12:36 pm
Location: Marlow, UK

Re: how to show the last comments?

Post by scooper »

You could just create a fairly simple user defined tag to pull out the last comments from the database (I'm assuming you're using the comments module). 

To pull the last 5 comments out for example you could create a tag with something like.

Code: Select all

global $gCms;
$db = & $gCms->GetDb();

$query = 'SELECT * FROM `cms_module_comments` ORDER BY `create_date` DESC LIMIT 5';
$result = $db->Execute($query);

while ($result && !$result->EOF)
{
	echo $result->fields['comment_data'];
	echo '<br />';

	$result->MoveNext();
}

and then just put that UDT wherever you wanted to display the latest comments.

You could of course pull other data out of the comments table if you want to display more info or make a link to the page it's on.

s.
presura
Forum Members
Forum Members
Posts: 20
Joined: Wed May 23, 2007 5:36 pm

Re: how to show the last comments?

Post by presura »

Hi Scooper,

Thanks for your help! I did write the code where I put a link, and it works! The modiefied is below.
I wonder, can you modify the code to show only the first 20 characters of the comment?
Again, thanks a lot,
cristian

******************

global $gCms;
$db = & $gCms->GetDb();

$query = 'SELECT * FROM `cms_module_comments` ORDER BY `create_date` DESC LIMIT 5';
$result = $db->Execute($query);

while ($result && !$result->EOF)
{
            echo 'fields['page_id'];
            echo '">';
echo $result->fields['comment_data'];
            echo '';

$result->MoveNext();
}
*******************
presura
Forum Members
Forum Members
Posts: 20
Joined: Wed May 23, 2007 5:36 pm

Re: how to show the last comments?

Post by presura »

Hmm, a bit of php does help... So I solved the length with the substr:

************
global $gCms;
$db = & $gCms->GetDb();

$query = 'SELECT * FROM `cms_module_comments` ORDER BY `create_date` DESC LIMIT 5';
$result = $db->Execute($query);

while ($result && !$result->EOF)
{
            echo substr($result->fields['comment_data'],0,100);
            // echo $result->fields['comment_date'];
            echo ' (fields['page_id'];
            echo '">';
echo 'la stire';
            echo ')';
echo '';echo '';

$result->MoveNext();
}
********
Post Reply

Return to “Developers Discussion”