Path to the first child page?

Permalink
Can someone please tell me how to programatically get the path to the first child page, to use that code in a custom block to create a link for an element of that block (image)?

I don't want to redirect the page, I just need the path to link an image of a custom block ( in view.php) to the first child page. If no child page exists, nothing should be output.

In other words: clicking on an image in a custom block should lead to the first child page.

How could that be done?

okapi
View Replies:
madesimplemedia replied on at Permalink Reply
madesimplemedia
I guess something like:

<?php
$pl = new \Concrete\Core\Page\PageList();
$pl->filterByParentID(21);  // Add parent page ID here.
$pages = $pl->getResults();
$n = 0;
foreach($pages as $page) {
    $n++;
    if($n == 1) {
         $path = $page->getCollectionPath();
    }
}
?>
<a href="<?php echo $path; ?>"><img ... ></a>
okapi replied on at Permalink Reply
okapi
Thanks, but the problem is, we have to get the ID first.
The custom block should get it by itself.

To be more precise: I have built a custom image block. The image displayed by this block should be linked to the first subpage of the page where the block is inserted.

The snippet I'm looking for would have to recognize the current page ID, the page ID of the first subpage and finally the path to the first subpage.
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
You should find what you need in this page
https://www.webli.us/cheatsheet/doku.php...
madesimplemedia replied on at Permalink Reply
madesimplemedia
$page = Page::getCurrentPage();
$pageID = $page->getCollectionID();


Then instead of adding 21 above, you can add $pageID
okapi replied on at Permalink Reply
okapi
Thank you very much for your help @madesimplemedia and @ConcreteOwl!
That code works fine, except if the block is placed on the start page (since then there is no parent page).
Could there be a solution?
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
Would you want to hide the block in this case, or what?
okapi replied on at Permalink Reply
okapi
No, the block should simply behave the same on the start page as on any other page: the image should point to the first subpage. Otherwise that block can only be used to a limited extent, which means that it would be easier to make the image link manually selectable.