Jump to content

Recommended Posts

Posted

Im having trouble with this … i hope there’s someone out there to help.

I have a bunch of pages with a multi-image (ImagesExtra module) field. My aim is to show all images from all pages in random order, accompanied with the title of the page they are on … I’m stuck on getting the page title after i’ve shuffled the array; I’m getting one and the same page title.

thank you!

 

  $thumbs = new WireArray();

  // get pages by template
  $posts = $pages->find('template=post_work’);

  foreach($posts as $post) {
    // get images, add to array
    foreach($post->images_extra as $thumb) $thumbs->add($thumb);
    }

    // shuffle array
    $random_thumbs = $thumbs->shuffle();

    foreach($random_thumbs as $r) {
      echo "<img src='{$r->url}'>
            <p>$post->title</p>";
    }

 

  • Like 1
Posted

A Pageimage instance knows the page it belongs to. See the bottom of the Pagefile documentation (section "Other") for reference.

    foreach($random_thumbs as $r) {
      echo "<img src='{$r->url}'>
            <p>{$r->page->title}</p>";
    }

 

  • Like 5

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
  • Recently Browsing   0 members

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