How To Add An Article's Author 'About Me' Details On The Article Page

Why an option to display the 'about me' user profile field in articles written by the user, is not yet a default function in a supreme CMS as Joomla, is indeed a mystery! Many Joomla users seek this ability, and if asked in the Joomla "support" forum, the so-called branded "joomla masters" tend to send the inquirer to the Joomla Extensions Directory to install yet another unnecessary addon. Stop It! Joomla is developed to be configurable.

The Method (see video guide below)

1. Create A Layout Override

Joomla is equipped with a superb template override system to manipulate most display files for your preferred appearance.

  • 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 Name author.php

html/layouts/joomla/content/info_block/author.php

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

// 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'];

 

then add the output variable where you desire

	<?php // the output
	if( !empty($authordetail) ) { ?>
	<div class="aboutme">
		<?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 } ?>

 

The completed file should look like this. A <div> wrap was added so the out put can be formatted with css.

<?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'];
//uncomment either of the following to see the available array values you can use to return any output
//print_r($displayData['item']);
//print_r(JUserHelper::getProfile($authorId)->profile);
?>
<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-profile-shown-with-article.jpg

 

Video Guide

CLICK_PLAY_BUTTON

Wednesday, 28 December 2016 05:33  |   303 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