depth
query parameter is higher than 0 (the default value is 1) so that the authors will be returned. Note that any other filtering or order you do to the article will not affect what items are returned within the Linked items element.
The following examples show how to retrieve a single article (named The Origin of Coffee) with its author (a linked item).
In the default JSON response, the codename for your author (jane
in our example) will appear in the value
of your author
element. If you had multiple authors, they would appear in the same order in the author
element as they do in the UI.
Jane's name and bio will appear in the modular_content
collection under her codename. So to use Jane within your article, all you have to do is match the codename from the author
element with the values you want to use from the jane
collection.
{
"item": {
"system": {
"id": "4735c956-4be4-482c-b874-bba201a22f44",
"name": "The Origin of Coffee",
"codename": "the_origin_of_coffee",
"language": "en-US",
"type": "simple_article",
"sitemap_locations": [],
"last_modified": "2020-02-03T12:36:02.7767984Z"
},
"elements": {
"title": {
"type": "text",
"name": "Title",
"value": "The Origin of Coffee"
},
"author": {
"type": "modular_content",
"name": "Author",
"value": [
"jane_doe"
]
},
"body": {
"type": "rich_text",
"name": "Body",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>The history of coffee is patchy and full of myth and hearsay. Although it's far more likely that uses for coffee were developed over time and were discovered by people tasting various parts of the cherry, the old fables do add a bit of romance and are very cute.</p>"
}
}
},
"modular_content": {
"jane_doe": {
"system": {
"id": "3bf1c09b-4552-4e2c-8de5-ffce79f773e0",
"name": "Jane Doe",
"codename": "jane_doe",
"language": "en-US",
"type": "author",
"sitemap_locations": [],
"last_modified": "2020-02-03T12:30:14.641708Z"
},
"elements": {
"name": {
"type": "text",
"name": "Name",
"value": "Jane Doe"
},
"bio": {
"type": "rich_text",
"name": "Bio",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>Jane is a fun-loving writer who enjoys her coffee black as hell, strong as death, and sweet as love.</p>"
}
}
}
}
}
<?php
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
// Defined by Composer to include required libraries
require __DIR__ . '/vendor/autoload.php';
use Kontent\Ai\Delivery\DeliveryClient;
$client = new DeliveryClient('8d20758c-d74c-4f59-ae04-ee928c0816b7');
$item = $client->getItem('the_origin_of_coffee', (new QueryParams())
->depth(1));
?>
depth
query parameter to 2 or more.