Search code examples
joomlaaliasauthor

Get the Author Name in Joomla 2.5


How do I get the authors name of the current article in Joomla 2.5?

I tried using this code but its giving me number;

$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_author = $article->created_by;
echo $article_author;

Solution

  • You can try like this

    //this method of getting requested variable is deprecated 
    $id = JRequest::getInt('id');
    
    //use JFactory::getApplication()->input instead of JRequest::getInt()
    
    $id = JFactory::getApplication()->input->getInt('id')
    $article = JTable::getInstance('content');
    $article->load($id);
    
    //get user id which create the article
    $created_user_id = $article->created_by;
    
    //fetch user
    $user = JFactory::getUser($created_user_id);
    $article_author = $user->name;
    echo $article_author;
    

    Hope this will help you.