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
how to show the last comments?
Re: how to show the last comments?
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.
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.
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.
Re: how to show the last comments?
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();
}
*******************
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();
}
*******************
Re: how to show the last comments?
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();
}
********
************
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();
}
********