Add Article Author Details To The Category List And Article Page

Add Article Author Details To The Category List And Article Page

Joomla has the greatest template override system among all the top CMS, but you won't know it if you don't use it. Adding an author's profile data to articles they wrote, is done simply.

1. Create A Layout Override

  • Go to Extensions > Templates
  • Click the name of your default template (highlighted star), under the column titled Template.
  • Click the tab labeled Overrides
  • Under the column titled Layouts, click Joomla then click content

The page will refresh and show the confirmation of the override creation. Now edit the file

  • Click the tab labeled Editor
  • Click through directories html > layouts > joomla > content > info_block
  • Click the file named author.php to open the code editor on the right

2. Edit The Override File Named author.php


Add the following code to the top within the <?php tag. This gets the ID the currently viewed article then creates an output variable of the user profile aboutme through the JUserHelper class.

 * @package     Joomla.Site
 * @subpackage  Layout
 * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt

defined('JPATH_BASE') or die;

// get author ID
$authorId = $displayData['item']->created_by;

// get user profile field data
$authordetail = JUserHelper::getProfile($authorId)->profile['aboutme'];
$authorwebsite = JUserHelper::getProfile($authorId)->profile['website'];

<dd class="createdby" itemprop="author" itemscope itemtype="">
   <?php $author = ($displayData['item']->created_by_alias ?: $displayData['item']->author); ?>
   <?php $author = '<span itemprop="name">' . $author . '</span>'; ?>
   <?php if (!empty($displayData['item']->contact_link ) && $displayData['params']->get('link_author') == true) : ?>
      <?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', $displayData['item']->contact_link, $author, array('itemprop' => 'url'))); ?>
   <?php else : ?>
      <?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', $author); ?>
   <?php endif; ?>
   <?php // the output
   if( !empty($authordetail) ) { ?>
   <div class="aboutme">
   <h4>About The Author</h4>
      <?php echo $authordetail; ?>
      <?php if( !empty($authorwebsite) ) { ?>
         <p><a href="/<?php echo $authorwebsite; ?>" rel="nofollow" target="_blank">Author's Website</a></p>
      <?php } ?>
   <?php } ?>

Now the article aboutme text will display where the article info is assigned. Of course you must enable Show Author either in the content global configuration, or in the menu item options.

The output

author details added