I am writing a theme for our team website and am currently using the category listing from com_contact to display a list of our team members. All members are in a single category called "Teammembers". We have an organizational structure, therefore I used the sorting fields on the contacts to sort them by organizational layers, as seen below:

Teammembers sorted by organizational layer but in single category

I want to take this a step further, showing the titles of the organizational layers, which led me to the conclusion that I'm better off using a categories listing instead, splitting the members into separate subcategories, and showing the contents (i.e. contact items) inside of the subcategories in the top view below their respective subcategory titles (see below).

Teammembers split into subcategories showing in categories view

Is there any way to render the items contained inside of all subcategories in a parent category? As far as I can tell I can only render out the subcategory (titles) themselves and not their children?

2 Answers 2


I finally solved it myself. I modified my com_contact category default_children template to load another template part (called it catitems):

<?php if ($child->numitems > 0 ) :
    $this->children[$child->id] = $child->getChildren();
    $this->category = $child;
    echo $this->loadTemplate('catitems');
    $this->category = $child->getParent();
endif; ?>

In default_catitems I included a database query to the contact_details table to gather all contacts with the current category's ID:

$db = JFactory
$query = $db->getQuery(true);
$query->select($db->quoteName(array('name', 'alias', 'con_position', 'email_to', 'telephone', 'fax', 'image', 'published', 'access', 'id')));
$query->where($db->quoteName('catid') . ' = '. $db->quote($cat_id));
$query->order('sortname2 ASC');

$results = $db->loadObjectList();

Sorting is done by sortname2 which contains the contact names with last name first. Pretty ugly to have that hardcoded here, but I'll fix that later.

Finally I iterate over $results to generate my contact list in the subcategory, which is basically a clone of the default_items template with minor modifications. Depending on the contents of the contact list, one might have to generate $item->slug in each loop iteration (is not part of the contact_details table):

<?php $item->slug=$item->id .':'. $item->alias; ?>
  • 1
    Hello @RivEpica and welcome to JSE. That's all good you have done, just you should do it in template override, because core changes might be overwritten on next Joomla upgrade. I am sure you can find enough informaton on template override here on JSE.
    – Mikan
    Commented Feb 17, 2016 at 11:32
  • 1
    @MirkoMikan Thank you! You're right, I wasn't too verbose about it but I actually did it in template override. It's just the "default" contact category template for the theme I'm developing. But it is part of the template, not in ./components/com_contact/views/category/tmpl/.
    – Jan W
    Commented Feb 17, 2016 at 11:50
  • Well, great then...
    – Mikan
    Commented Feb 17, 2016 at 11:52
  • User @SNeppers has asked "Hope it is not to much to ask, but could you please show more in detail how you accomplished this? I am having trouble to find out what to use and modifiy from the default_items.php into the default_catitems.php. I would be so thankful."
    – TryHarder
    Commented Nov 15, 2016 at 23:06

For Category view in file default_children.php after tag <li... add code:


    // Get Category Model data
    $categoryModel = JModelLegacy::getInstance('Category', 'ContactModel', array('ignore_request' => true));

    $categoryModel->setState('category.id', $child->id);
    $categoryModel->setState('list.ordering', 'a.name');
    $categoryModel->setState('list.direction', 'asc');
    $categoryModel->setState('filter.published', 1);

    $contacts = $categoryModel->getItems();


For Custom Fields add first line after previus code, and in cycle get custom field for each contact:

JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
foreach($contacts as $contactItem) {
    $currentContFields[] = FieldsHelper::getFields('com_contact.contact', $contactItem, true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.