Morphosis Posted June 2 Share Posted June 2 Hi all, Ive create a page reference select list in admin to show a small number of images from a child page. <?php $int = 1026; foreach ($pages->get($int)->gallery_images as $photo): ?> <?php //$thumb = $photo->size(480, 320); ?> <div class="col"> <a class="gallery-item" href="<?= $photo->url; ?>"> <img src="<?= $photo->url; ?>" class="img-fluid rounded" alt="<?= $photo->description; ?>"> </a> </div> <?php endforeach; ?> I also have a link to the page reference too. <a href="<?= $page->gallery_cta_source->url; ?>" class="button button-border button-dark button-rounded mt-4">View full gallery</a> The above works when I set the $int = 1026, However, I want to use '$page->gallery_cta_source' which is the page id as a string. I have tried converting it to a int and use it but getting error: 'Object of class ProcessWire\Page could not be converted to int in...' <?php $string = $page->gallery_cta_source; $int = intval($string); foreach ($pages->get($int)->gallery_images as $photo): ?> Any advice or better options then I'm all ears! Thanks in advance. Link to comment Share on other sites More sharing options...
cwsoft Posted June 2 Share Posted June 2 Have you tried a simple var_dump($int); exit; after your third line of the last code block in your template file? Then I would to a $match = $pages->get('id=' . $int); var_dump($match); exit; to see if your result is a null page or a match. For debugging I would install Tracy Debugger from the PW module repository and then just add some bd($object); calls to get an idea of whats going on. 1 Link to comment Share on other sites More sharing options...
Robin S Posted June 2 Share Posted June 2 @Morphosis, the value of a populated "single" Page Reference field... ...is a Page object. So it's redundant to get the ID of the Page Reference field value and then get the Page object from the ID, because you already have the Page object. So you probably want something like this: // If the Page Reference field is populated (i.e. its value is not a NullPage having an ID of zero) // and there are some images uploaded to the selected page if($page->gallery_cta_source->id && $page->gallery_cta_source->gallery_images->count) { // Then output the images foreach($page->gallery_cta_source->gallery_images as $image) { // ... } } 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now