Custom fields on parent page

Post Reply
User avatar
bayerberg
Master Bludit
Posts: 142
Joined: Wed Jun 07, 2017 1:05 pm
Location: London, UK
Has thanked: 10 times
Been thanked: 10 times
Contact:

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...
bludit plugins and themes - makeitblu | I do things, check them out on behance and dribbble.
User avatar
Misteric
Ssr. Bludit
Posts: 16
Joined: Mon Aug 08, 2022 2:55 pm
Has thanked: 3 times
Been thanked: 6 times

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
User avatar
bayerberg
Master Bludit
Posts: 142
Joined: Wed Jun 07, 2017 1:05 pm
Location: London, UK
Has thanked: 10 times
Been thanked: 10 times
Contact:

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.
bludit plugins and themes - makeitblu | I do things, check them out on behance and dribbble.
Post Reply