3fingers Posted April 24, 2016 Share Posted April 24, 2016 Hey guys, I'm running into a problem: <?php // my images field is named "filter_image": $pagesWithImages = $pages->find("filter_image.count>0"); $filtered = array(); foreach($pagesWithImages as $p) { foreach($p->filter_image as $image) $filtered[] = $image; }; $out= ""; foreach($filtered as $filter){ $out .="<div class='filter-box' style='background-image: url({$filter->url});'>"; $out .= "<div class='uk-overlay uk-overlay-hover uk-position-cover'>"; $out .= "<div class='uk-overlay-panel uk-position-cover uk-overlay-background uk-overlay-fade uk-flex uk-flex-center uk-flex-middle'>"; $out .= "<a class='hover-btn' href='{$p->url}'>{$filter->description}</a>"; // How can I get the url of the page the image belongs? $out .="</div></div></div>"; } echo $out; ?> This code works fine, but how can I get the url of the page the image belongs? I'm tired and I cannot find the right answer.... Any advice? Thanks! Link to comment Share on other sites More sharing options...
DaveP Posted April 24, 2016 Share Posted April 24, 2016 You can do $file->page (http://cheatsheet.processwire.com/files/file-properties/file-page/) so $filter->page->url should work. 2 Link to comment Share on other sites More sharing options...
3fingers Posted April 24, 2016 Author Share Posted April 24, 2016 Thanks @DaveP, it worked flawlessly. Next time I'll take a closer look at the cheatsheet Link to comment Share on other sites More sharing options...
Robin S Posted April 24, 2016 Share Posted April 24, 2016 Another way you could do this (code style may not be to your taste): <?php $pagesWithImages = $pages->find("filter_image!=''"); ?> <?php foreach($pagesWithImages as $p): ?> <?php foreach($p->filter_image as $filter): ?> <div class="filter-box" style="background-image: url(<?= $filter->url ?>);"> <div class="uk-overlay uk-overlay-hover uk-position-cover"> <div class="uk-overlay-panel uk-position-cover uk-overlay-background uk-overlay-fade uk-flex uk-flex-center uk-flex-middle"> <a class="hover-btn" href="<?= $p->url ?>"><?= $filter->description ?></a> </div> </div> </div> <?php endforeach; ?> <?php endforeach; ? 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