Jump to content

page->url based on image


3fingers
 Share

Recommended Posts

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

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; ?
  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...