There used to be sitemaps functionality but it got deprecated. Taxonomies are suggested as a replacement but when I request items from the API, the taxonomy elements lack the hierarchical structure. How do I search for an item that represents a parent page in website structure? Thank you.
You can still do that with Delivery API. First, you need to create and and organize your taxonomy group the same way you would organize your sitemap. Consider following sitemap as an example:
This is what the taxonomies would look like in Kentico Cloud:
Models for your items need to be created with taxonomy element, that would serve as a sitemap location selector. When you retrieve this element from the item, it will give you a list of terms that the item is associated with. If you tick two terms with the item (Contact us, Our team), this is what the element would look like in the API:
{
"item": {
"system": {
"id": "8a9e7010-c79b-41c5-a0bc-4f20c9c233b8",
"name": "Example item - contact form",
"codename": "example_item___contact_form",
"language": "default",
"type": "example_content_model",
"sitemap_locations": [],
"last_modified": "2019-05-13T08:20:50.3173519Z"
},
"elements": {
"sitemap": {
"type": "taxonomy",
"name": "Sitemap",
"taxonomy_group": "sitemap",
"value": [
{
"name": "Contact Us",
"codename": "contact_us"
},
{
"name": "Our team",
"codename": "our_team"
}
]
}
}
},
"modular_content": {}
}
As you can see you get information about taxonomy group codename and a flat list of name and codename pairs of each ticked term. To get the hierarchical structure, you need to make second call to retrieve the taxonomy group, which will yield following:
{
"system": {
"id": "0b4e3da2-8699-4b4d-961c-1fe912c91570",
"name": "Sitemap",
"codename": "sitemap",
"last_modified": "2019-05-13T08:01:34.6109452Z"
},
"terms": [
{
"name": "Home",
"codename": "home",
"terms": []
},
{
"name": "About",
"codename": "about",
"terms": [
{
"name": "Our team",
"codename": "our_team",
"terms": [
{
"name": "Management",
"codename": "management",
"terms": []
},
{
"name": "Contact Us",
"codename": "contact_us",
"terms": []
}
]
},
{
"name": "Mission & Values",
"codename": "mission___values",
"terms": []
}
]
}
]
}
Which reflects needed hierarchy. You can compare the codenames you got from your item to the position of the taxonomy term in your group - to get the parent taxonomy term just get the parent JSON node. If you need to figure out the parent item itself, you can call Delivery API again and use one of the array filters to get all the items marked with the parent sitemap location.