Latest Comments List [solved]

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
ankel
Forum Members
Forum Members
Posts: 16
Joined: Tue Mar 28, 2006 10:33 am

Latest Comments List [solved]

Post 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
Last edited by ankel on Tue Feb 27, 2007 11:23 am, edited 1 time in total.
cyberman

Re: Latest Comments List

Post 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 ...
ankel
Forum Members
Forum Members
Posts: 16
Joined: Tue Mar 28, 2006 10:33 am

Re: Latest Comments List

Post 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
}
?>
cyberman

Re: Latest Comments List [solved]

Post by cyberman »

Thanks for posting your solution ...
Klassiekerrally
Forum Members
Forum Members
Posts: 64
Joined: Thu Nov 08, 2007 6:18 pm

Re: Latest Comments List [solved]

Post 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...
ankel
Forum Members
Forum Members
Posts: 16
Joined: Tue Mar 28, 2006 10:33 am

Re: Latest Comments List [solved]

Post 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. :)
Klassiekerrally
Forum Members
Forum Members
Posts: 64
Joined: Thu Nov 08, 2007 6:18 pm

Re: Latest Comments List [solved]

Post by Klassiekerrally »

It works! Thank you very much.
Pierre M.

Re: Latest Comments List [solved]

Post 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.
soupaloignon
Forum Members
Forum Members
Posts: 36
Joined: Sat Dec 02, 2006 7:08 pm

Re: Latest Comments List [solved]

Post 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 ;))
voxberry
Forum Members
Forum Members
Posts: 56
Joined: Tue Sep 01, 2009 1:04 pm

Re: Latest Comments List [solved]

Post 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 ;) .
Post Reply

Return to “Tips and Tricks”