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

html/layouts/joomla/content/info_block/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.

<?php
/**
 * @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'];

//print_r($displayData['item']);
?>
<dd class="createdby" itemprop="author" itemscope itemtype="https://schema.org/Person">
   <?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 } ?>
   </div>
   <?php } ?>
</dd>

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


Saturday, 27 May 2017 02:21  |   359 views

 

Copyright © 2017 CMSEnergizer.com. All Rights Reserved.
This website is powered by the Joomla!©™ 3 Website Framework | File download and article manager component by K2 | Advanced Module Manager and Modules Anywhere by NoNumber Elements | Website hosting and development by WebsiteDons

CMSEnergizer.com is owned and operated by Emuzement Net Inc, 4532 West Kennedy Blvd. Ste 180 33609 Tampa, Florida USA