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

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
User avatar
websitedons
I've been banned!
Posts: 389
Joined: Sat May 27, 2017 9:42 am

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

Post by websitedons » Mon Jun 26, 2017 7:17 am

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.

Simply replace all the coding with the below.

Code: Select all

<?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-profile-shown-with-article.jpg
You do not have the required permissions to view the files attached to this post.

User avatar
websitedons
I've been banned!
Posts: 389
Joined: Sat May 27, 2017 9:42 am

Add A Profile Image Field To User Registration

Post by websitedons » Tue Jun 27, 2017 3:17 am

A request was submitted to include user profile photo field, and again because of the superior Joomla JForm system, adding the field is quite simple.

Create A System Plugin
If you have been following our series of custom form field insertion, and have already created a system plugin, you don't need create a new plugin for each field. Just add as needed.

1. Create the folder which will contain all the files and give it a relative name
my_custom_fields

2. Create the primary function file within the folder and keep the name similar to the folder for simplicity
my_custom_fields.php

Code: Select all

<?php defined('_JEXEC') or die();
/**
* @package      plg_system_my_custom_fields
* @copyright   Copyright (C) AnySiteYouWantHere.com All rights reserved.
* @license      GNU General Public License version 2 or later; see http://www.gnu.org/licenses/
**/

class plgSystemMy_Custom_Fields extends JPlugin {

   public function onContentPrepareForm($form, $data) {
   	
   	//define field file path
   	$formFields = JForm::addFormPath(JPATH_PLUGINS.'/system/my_custom_fields/form/';
   	
      // get the form field xml
      if( $form->getName() == 'com_users.user' ) {
         $formFields;
         $form->loadFile('user-profile', false);
      }
   }

}
3. Create the installer XML file within the folder and give it the same name as the function file
my_custom_fields.xml

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.7.0" type="plugin" group="system" method="upgrade">
   <name>System - My Custom Fields</name>
   <author>AnyWebSiteHere.com</author>
   <creationDate>06.26.2017</creationDate>
   <copyright>All Rights Reserved.</copyright>
   <license>license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html</license>
   <authorEmail>yourmail@yoursite.com</authorEmail>
   <authorUrl>http://www.yoursitehere.com</authorUrl>
   <version>1.0</version>
   <description>A list of custom fields to enhance the Joomla abilities</description>
   
   <files>
      <filename plugin="my_custom_fields">my_custom_fields.php</filename>
      <filename>index.html</filename>
     <folder>form</folder>
   </files>
</extension>
4. Create a directory named form inside the parent directory and create a file named user-profile.xml
user-profile.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="profile">
	<fieldset name="profile" label="PLG_USER_PROFILE_SLIDER_LABEL">
		<field name="avatar" type="media" directory="images" label="Avatar" />
	</fieldset>
</fields>
</form>
The new field will appear at the top of the profile fields.
user-profile-field.jpg
Display Profile Image With Article Author Details
Add to the overridden author.php
$authoravatar = JUserHelper::getProfile($authorId)->profile['avatar'];
Then output with <img src="<?php echo $authoravatar; ?>" />

Code: Select all

<?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'];
$authoravatar = JUserHelper::getProfile($authorId)->profile['avatar'];

?>
<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 if( !empty($authoravatar) ) { ?>
		<img src="<?php echo $authoravatar; ?>" />
		<?php } ?>
		<?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>

Style as desired.

The output
author-details-with-profile-photo.jpg
You do not have the required permissions to view the files attached to this post.

Carlos_Mendez
Joomla! Apprentice
Joomla! Apprentice
Posts: 13
Joined: Wed Sep 06, 2017 4:17 pm

Re: How To Add An Article's Author 'About Me' Details On The Article Page Without Additional Extensions

Post by Carlos_Mendez » Thu Nov 16, 2017 11:27 am

Great post. Are the fields used ("aboutme" and "website") custom fields? I can't find in the user management settings.

User avatar
DV-admin
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 129
Joined: Wed Sep 20, 2017 7:24 am
Location: Genova
Contact:

Re: How To Add An Article's Author 'About Me' Details On The Article Page Without Additional Extensions

Post by DV-admin » Thu Nov 23, 2017 6:48 pm

Carlos_Mendez wrote:Great post. Are the fields used ("aboutme" and "website") custom fields? I can't find in the user management settings.
I agree with Carlo however like him I cannot find these user settings anywhere. In fact I have an About th e Author text there and I dont know where to change it.


Locked

Return to “Joomla! 3.x Coding”