Page 1 of 1
Latest Comments List [solved]
Posted: Tue Feb 27, 2007 8:54 am
by ankel
Hello,
Sorry about my english.
Is there any function in comments module to show off latest comments in global mode (i.e. on first/main page)?
Maybe with link to this comments/articles ?
If not - maybe there is a simple way to do something like that list of new comments?
Thank You for any help.
Greetings
Marek
Re: Latest Comments List
Posted: Tue Feb 27, 2007 9:12 am
by cyberman
Think there's no function like this.
But there exists a tag on default install named "recently updated". Shouldn't be too difficult to modify it for using with comments ...
Re: Latest Comments List
Posted: Tue Feb 27, 2007 11:22 am
by ankel
I wrote something like that, and working fine
Code: Select all
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function smarty_cms_function_latest_comments($params, &$smarty)
{
if(empty($params['number']))
{
$number = 5;
}
else
{
$number = $params['number'];
}
$output = '<ul>';
global $gCms;
$hm =& $gCms->GetHierarchyManager();
$db = &$gCms->db;
// Get list of most recently updated pages excluding the home page
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE active = 1 ORDER BY modified_date DESC LIMIT ".$number;
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
while ($dbresult && $updated_page = $dbresult->FetchRow())
{
$curnode =& $hm->getNodeById($updated_page['comment_id']);
$output .= '<li>';
$output .= '<a href="http://rzepin.net/news/'.$updated_page['page_id'].'">'.substr($updated_page['comment_data'], 0, 40).' (...)</a>';
$output .= ' Napisano: ' .$updated_page['modified_date'];
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
function smarty_cms_help_function_latest_comments() {
?>
<h3>What does this do?</h3>
<p>Outputs a list of latest comments.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like: <code>{latest_comments}</code></p>
<h3>What parameters does it take?</h3>
<ul>
<li><p><em>(optional)</em> number='5' - Number of updated pages to show.</p><p>Example: <pre>{recently_updated number='15'}</li>
</ul>
</p>
<?php
}
function smarty_cms_about_function_latest_comments() {
?>
<p>Author: Marek Pych basing on "recently updated" by Elijah Lofgren <elijahlofgren@elijahlofgren.com></p>
<p>Version: 1.0</p>
<p>
Change History:<br/>
None
</p>
<?php
}
?>
Re: Latest Comments List [solved]
Posted: Tue Feb 27, 2007 12:09 pm
by cyberman
Thanks for posting your solution ...
Re: Latest Comments List [solved]
Posted: Fri Jan 18, 2008 7:07 am
by Klassiekerrally
I'd like to use the 'latest comments' function in my website too. (
www.klassiekerrally.nl)
Where can I find how to put the right pieces of code in tags?
Somehow I can't get it to work...
Thanks for any help...
Re: Latest Comments List [solved]
Posted: Fri Jan 18, 2008 7:23 am
by ankel
It's quite simple.
You must create plugin file: function.latest_comments.php in /plugins/
Then paste the code of plugin in this file:
Code: Select all
<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://cmsmadesimple.sf.net
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function smarty_cms_function_latest_comments($params, &$smarty)
{
if(empty($params['number']))
{
$number = 5;
}
else
{
$number = $params['number'];
}
$output = '<ul>';
global $gCms;
$hm =& $gCms->GetHierarchyManager();
$db = &$gCms->db;
// Get list of most recently updated pages excluding the home page
$q = "SELECT * FROM ".cms_db_prefix()."module_comments WHERE active = 1 ORDER BY modified_date DESC LIMIT ".$number;
$dbresult = $db->Execute( $q );
if( !$dbresult )
{
echo 'DB error: '. $db->ErrorMsg()."<br/>";
}
while ($dbresult && $updated_page = $dbresult->FetchRow())
{
$curnode =& $hm->getNodeById($updated_page['comment_id']);
$output .= '<li>';
$output .= '<a href="http://<your_site>/news/'.$updated_page['page_id'].'">'.substr($updated_page['comment_data'], 0, 40).' (...)</a>';
$output .= ' Added: ' .$updated_page['modified_date'];
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
function smarty_cms_help_function_latest_comments() {
?>
<h3>What does this do?</h3>
<p>Outputs a list of latest comments.</p>
<h3>How do I use it?</h3>
<p>Just insert the tag into your template/page like: <code>{latest_comments}</code></p>
<h3>What parameters does it take?</h3>
<ul>
<li><p><em>(optional)</em> number='5' - Number of updated pages to show.</p><p>Example: <pre>{recently_updated number='15'}</li>
</ul>
</p>
<?php
}
function smarty_cms_about_function_latest_comments() {
?>
<p>Author: Marek Pych basing on "recently updated" by Elijah Lofgren <elijahlofgren@elijahlofgren.com></p>
<p>Version: 1.0</p>
<p>
Change History:<br/>
None
</p>
<?php
}
?>
Replace from code with url of your site. Do you have pretty urls? If yes it's simple, if not - better if you active this feature.
Now put somewhere {latest_comments} in you site, and ... done.
I hope you understand me with my english
On site:
http://rzepin.net latest comments working poperly.

Re: Latest Comments List [solved]
Posted: Sun Jan 27, 2008 11:14 am
by Klassiekerrally
It works! Thank you very much.
Re: Latest Comments List [solved]
Posted: Tue Jan 29, 2008 3:29 pm
by Pierre M.
@ankel : Thank you very much for the tip. Feel free to add this cool plugin in the wiki. You have write access with your forum account.
Have fun with CMSms !
Pierre M.
Re: Latest Comments List [solved]
Posted: Tue Jun 02, 2009 10:04 am
by soupaloignon
Hi (sorry for my english, i'm french

)
This script don't work now . The list is good, with comments. but the link is bad (page doesn't exist)
you have a solution ?
thanks
(pfeuuu, mon anglais est vraiment naze

)
Re: Latest Comments List [solved]
Posted: Thu Sep 10, 2009 7:08 pm
by voxberry
soupaloignon : dude, i think you did not do the pretty url thing, that's why the link is dead .
This is a great peace of code mate. thank you
I'm also using this and it works great

.