The majority of the time, when I need to get data that is stored in the database, depending on the situation, I tend to stick to database queries as they are more flexible.
You could use the following:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('title')))
->from($db->quoteName('#__categories'))
->where($db->quoteName('parent_id') . ' != 1'0')
->where($db->quoteName('extension') . ' = ' . $db->quote('com_content'));
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach ($rows as $row)
{
echo '<p>' . $row->title . '</p>';
}
As you can see, the parent_id
must be 1
and the categories must belong to com_content
(to prevent pullingThis will get all categories for com_content apart from the likes of com_weblinks
etc)very root category.
I've added in a little foreach
loop to display the title of the category for each result.
Hope this helps