Page 1 of 1

How to get authors e-mail (News)

Posted: Sat Sep 26, 2009 9:55 pm
by korpirkor
1. Create new User Defined Tag called author_email

Code: Select all

global $author_email, $gCms;

$smarty =& $gCms->GetSmarty();
$db =& $gCms->GetDb();
$config =& $gCms->GetConfig();

$id = $params['username'];
$def = $params['default'];


if(!empty($id))
{
	if(!isset($author_email[$id]))
	{
		$query = 'SELECT email FROM `'.$config["db_prefix"].'users` WHERE username LIKE "'.$id.'" LIMIT 1';
		$dbresult = $db->Execute($query);
		if($dbresult)
		{
			$row = $dbresult->FetchRow();
			$author_email[$id] = $row['email'];
		}
		else
			$author_email[$id] = $def;
	}
	
	if( isset($params['assign']) )
	{
		$smarty->assign($params['assign'], $author_email[$id]);
		return;
	}

	echo $author_email[$id];
}
2. In news template:

Code: Select all

Author <a href="mailto:{author_email username=$entry->author default="default@address.com"}">{$entry->authorname}</a>
-- edited: 29.09.2009 --