I have developed with help of @seagul code that changes output data for K2 Authors. It adds to article an author which created the item + another authors based on author_ID located in Author alias field. This code is called in K2 overrided templates item.php, category_item, user.php etc.
Code example:

This hack loads article authors
1] author where author= user
2] users where author id is in fiels article alias
$authors = array();

$authorsSql = $this->item->created_by; // add first author ID
if(!empty($this->item->created_by_alias)){ // if alias found...
  $authorsSql .= ','.$this->item->created_by_alias; // load Author IDs from Author Alias 
  $authorsSql = str_ireplace(',', ' OR userID=', 'userID='.$authorsSql); // prepare for SQL query 

  $dbo = JFactory::getDBO(); // prepare database
  $query = $dbo->getQuery(true); // prepare query
  $query->select('*'); // load all
  $query->from('#__k2_users'); // k2 users table
  $query->where($authorsSql); // only selected authors
  $query->order('userName ASC'); // order alphabeticaly by name

  $dbo->setQuery($query); // run query

  $rows = $dbo->loadObjectList(); // make query

  foreach($rows as $row) { // iterate through results
    $result .=  '<p>'.$row->userName.'</p>'; // add name to list
    $authors[] = array( // add author to array
                   'id' => $row->userID,
                   'name' => $row->userName

This similar code must be placed in every overrided template. This is not ideal for future code development of this feature.
Question: Is possible to make some __hook or alike function in one place that will alter the article output data which goes to template? That I can only grab this data in template and print it?

  • 1
    What about a k2 plugin? – Shaz May 28 '14 at 13:20
  • Yes, it seems as right direction, @Shaz thanks for advice. I'm still new in Joomla and learning the Joomla think-structure every line of code written. – Fanger Jun 1 '14 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.