Page 1 of 1
Custom fields on parent page
Posted: Thu Mar 21, 2024 9:56 pm
by bayerberg
Hi all!
How to check if the parent page has anything in custom field 'xxx'? We have $page->parentMethod() but dont think we can fetch $page->custom('xxx') through that...
Re: Custom fields on parent page
Posted: Sun Mar 24, 2024 4:16 pm
by Misteric
Hi Bayerberg,
1. List all the pages.
2. Check first if it's a parent page.
3. Afterwards you check if it has a custom field...
You can do something like that:
Code: Select all
<?php
// Page number of the paginator, the first page is 1
$pageNumber = 1;
// The value -1 tell to Bludit to returns all the pages on the system
$numberOfItems = -1;
// Only get the pages with the satus published
$onlyPublished = true;
// Get the list of keys of pages
$items = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
foreach ($items as $key) {
// buildPage function returns a Page-Object
$page = buildPage($key);
// The variable $page is an Page-Object
if ($page->hasChildren())) {
echo 'The page is a parent page';
if($page->custom('ZZZ')) {
echo 'You can sleep now on your 2 ears';
}
} else {
echo 'The page isn't a parent page';
}
}
?>
Hope it's helpfull
,
Misteric
Re: Custom fields on parent page
Posted: Mon Mar 25, 2024 11:32 pm
by bayerberg
Thanks! That was almost it
I'm after something a bit more elaborate. I want to show custom fields of a parent page on a child page.