Category sorting for API => JavaScript
Posted: Thu Nov 05, 2015 10:41 am
Hi all,
Just want to add a tip which might help someone using the API for front end.
Above call returns catagories ordered by their ID and since moving categories around in the top level will effectively change their ID, the ordering will break for when looping through the object in JavaScript. If you intend to create a sub-level UL LI UL LI for instance.
Easy fix.
In /phpmyfaq/inc/PMF/Catagory.php look for and change to
Result will be an ordering where all top level categories are situated first within the returned JSON but still ordered as per ordering in Admin. Followed by their closest sub-level categories, followed by their closest sub-level categories etcetera.
Cheers
/Simon
Just want to add a tip which might help someone using the API for front end.
Code: Select all
api.php?action=getCategories
Easy fix.
In /phpmyfaq/inc/PMF/Catagory.php look for
Code: Select all
private function getOrderedCategories($withperm = true){}
Code: Select all
GROUP BY
fc.id, fc.lang, fc.parent_id, fc.name, fc.description, fc.user_id
ORDER BY
fc.id",
PMF_Db::getTablePrefix(),
Code: Select all
GROUP BY
fc.id, fc.lang, fc.parent_id, fc.name, fc.description, fc.user_id
ORDER BY
fc.parent_id,fc.id",
PMF_Db::getTablePrefix(),
Cheers
/Simon