esedic
9/15/2016 - 6:30 AM

Get the name of the article author of the currently viewed article in Joomla

Get the name of the article author of the currently viewed article in Joomla

<?php
defined('_JEXEC') or die;

$app	= JFactory::getApplication();
$id		= $app->input->getInt('id');
$user	= JFactory::getUser();

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query
    ->select($db->quoteName(array('b.name')))
    ->from($db->quoteName('#__content', 'a'))
    ->join('INNER', $db->quoteName('#__users', 'b'). ' ON (' . $db->quoteName('a.created_by'). ' = '. $db->quoteName('b.id'). ')')
    ->where('a.id = ' . (int) $id);
// echo $query;
$db->setQuery($query);
$result = $db->loadResult();
//echo 'Name of the article author: '.$result;