PHP Templating API: getCategories()
Posted by Mark [Elevated X Support], Last modified by AJ Hall on 30 October 2017 12:31 PM

Description:

The getCategories() function gets a list of categories that are present in the system. Based on the arguments that are passed to it will determine which and how many categories are returned.

Sample Usage:

$categoryobj = $api->getCategories();

$categoryobj = $api->getCategories(["id" => 1]);

$categoryobj = $api->getCategories([
"parentid" => 1,
"subsiteid" => 1,
"has_sets" => 1,
"sort" => "date",
"sort_reverse" => "1",
"countonly" => 0,
]);

echo "\nNumber of categories returned: " . $categoryobj->categorycount;
echo "\nNumber of categories total: " . $categoryobj->categorytotal;
echo "\nNumber of pages: " . $categoryobj->numpages;
echo "\nCategories:\n";
print_r($categoryobj->categories);

Returning Attributes:

This function call will return a StdObject object with the following attributes:

categories:

This is a multi-dimensional array that returns any categories that match search criteria.

categorycount:

The number of categories within the categories attribute.

Arguments:

parentid:

If set, only show categories that have a specific category id as its parent category. This is useful, for instance, to only retrieve categories that are children of the "Tags" category.

By default, the system does not filter by category id if this value is not specified.

subsiteid:

If specified, limit categories that have sets belonging to a specified all-access subsite id. If this value is category to 0, show categories from all sites. Must be used in conjunction with the has_sets attribute.

By default, the system will detect if the current area belongs to an all-access subsite, and use that value.

Note: If you specify a non-zero value for subsiteid, all-access must be available within this system. Otherwise, an Exception will be triggered.

has_sets:

If set to 1, only retrieve categories that have active sets assigned to these categories.

By default, the system fetches all categories regardless of which sets are assigned to them.

sort:

Specify sorting order of categories.

Valid values are: id and title.

By default, the system will sort by id.

sort_reverse:

If this is category to 1, reverse the sorting order as specified within "sort"

countonly:

If specified, only return the number of categories that fit the search criteria.

(1 vote(s))
Helpful
Not helpful

Comments (0)