When using the TinyMCE editor, how can I display the username at the top of an article?
4 Answers
You can't display dynamic data this way through an article by default, as the editors won't process php.
However, to your rescue, there are plugins for this.
You can install Regular Lab's Sourcerer Plugin, and now you can write php, or other code directly in your articles.
It even supports some of the most common Joomla variables and Objects, which are ready to use. JUser is one of these, so all you need to display user data is a code inside your article like below:
{source}
<?php echo $user->username; ?>
{/source}
For more info about User Profile see: How to display user profile information?
The other way to display dynamic date in your article is to modify the article's template with an override and put all your php code in there.
Joomla Template/Layout Overrides Links
Download, install and enable a plugin name DirectPHP. This plugin gives the facility to write PHP code in article. After these in your article write following code.
<?php
jimport( 'joomla.user.helper' );
$user = JFactory::getUser();
echo $user->username;
?>
-
1
If you want to see the author on your website you have to change the settings of the article. System > Global Configuration > Articles and go to tab: "Articles" and look for "Show Author" and activate it.
The following extension might help adding user field values to content: https://extensions.joomla.org/extension/edition/user-field-values-in-articles/ .
This extension basically allows you to add user field values to content in Joomla! via a editor button or using placeholders. Some custom field types I see are also supported.