Show author username instead of real name in category blog - Joomla! Forum - community, help and support
hi, the title say, show author username instead of real name. found line in(\public_html\components\com_content\views\category\tmpl\blog_item.php)
i tried put ->username didn't works.
thanks in advance answers
code: select all
<?php if ($params->get('show_author') && !empty($this->item->author )) : ?>
<dd class="createdby">
<?php $author = $this->item->author; ?>
<?php $author = ($this->item->created_by_alias ? $this->item->created_by_alias : $author);?>
<?php if (!empty($this->item->contactid ) && $params->get('link_author') == true):?>
<?php echo jtext::sprintf('com_content_written_by' ,
jhtml::_('link', jroute::_('index.php?option=com_contact&view=contact&id='.$this->item->contactid), $author)); ?>
<?php else :?>
<?php echo jtext::sprintf('com_content_written_by', $author); ?>
<?php endif; ?>
</dd>
<?php endif; ?>i tried put ->username didn't works.
thanks in advance answers
you can't use 'username' directly because username not in object loaded. there 2 user related information loaded in object name , email. may make use of email (since email unique in joomla!) , cross check against database username. please add following lines after <dd class="createdby"> before <?php $author = $this->item->author; ?>
then, may make use of $username username display.
please avoid hacking existing files prevent future joomla! update issue, make use of layout override of joomla!
1) create new folder called com_content in html folder inside default frontend template
2) create new folder called category inside new com_content folder
3) copy blog_item.php file , put inside
4) apply coding changes
these safer way. may try understand more http://docs.joomla.org/understanding_output_overrides
code: select all
<?php
$db = jfactory::getdbo();
$query = $db->getquery(true);
$query->select($db->quotename('username'));
$query->from($db->quotename('#__users'));
$query->where($db->quotename('email') . ' = ' . $db->quote($this->item->author_email));
$db->setquery($query);
$username = $db->loadresult();
if ($db->geterrornum()) {
jerror::raisewarning(500, $db->geterrormsg());
return false;
}
?>
then, may make use of $username username display.
please avoid hacking existing files prevent future joomla! update issue, make use of layout override of joomla!
1) create new folder called com_content in html folder inside default frontend template
2) create new folder called category inside new com_content folder
3) copy blog_item.php file , put inside
4) apply coding changes
these safer way. may try understand more http://docs.joomla.org/understanding_output_overrides
Comments
Post a Comment