Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created July 30, 2014 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betweenbrain/a6ed70c49f98852aae48 to your computer and use it in GitHub Desktop.
Save betweenbrain/a6ed70c49f98852aae48 to your computer and use it in GitHub Desktop.
Sort Joomla items by parent
<?php
$query
->select($this->db->quoteName(array(
'title',
'id',
'parent_id')))
->select($this->db->quoteName('metadesc', 'description'))
->from($this->db->quoteName('#__categories'))
->order($this->db->quoteName('parent_id') . ' ASC')
->order($this->db->quoteName('ordering') . ' ASC');
$children = array();
if ($items)
{
foreach ($items as $item)
{
$list = @$children[$item->parent] ? $children[$item->parent] : array();
array_push($list, $item);
$children[$item->parent] = $list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment