Trying to make a Gallery from all images from a folder children

Hey all,

Im trying ALL photos from ALL my posts in a certain folder (Journal) and present them in a mega gallery. Been playing with this a bit, but I can’t figure it out. Seems like it should be simple. Need help!


This should grab all images from the children:

<?php foreach(page('journal')->files()->filterBy('type', 'image') as $image) : ?>
  <img src="<?php echo $image->url() ?>">
<?php endforeach ?>
1 Like

Woah thanks for the quick reply! Nothing seems show up though and Im not getting any errors. But to change direction a little bit Im using a gallery plugin and this is what I use now to grab images from a page.

 <?php	$images = $page->images()->sortBy('name', 'desc');
echo guggenheim($images, array('width' => 1200, 'height' => 350, 'border' => 8)); ?>

Any way to take your solution and mix it in with that? Excuse my basic php skills

What is $page in your code? The journal page?

  $images = $page->children()->files()->filterBy('type', 'image')->sortBy('name', 'desc');
  echo guggenheim($images, array('width' => 1200, 'height' => 350, 'border' => 8)); 

Pls. turn on debugging in your config.php:

c::set('debug', 'true');

As hard as I try, I sometimes overlook some of my typos :worried:

1 Like

The $page is just the current page Im not making any extra calls.

debug is (always) on. Thanks for your help

 <article class="post fadein">
      <header class="articletop">
    <h1><?php echo html($page->title()) ?></h1></header>
    <?php echo kirbytext($page->text()) ?>
 <?php	$images = $page->images()->sortBy('name', 'desc');
echo guggenheim($images, array('width' => 1200, 'height' => 350, 'border' => 8)); ?>
1 Like

I just tested this without using the plugin. Let’s suppose I had a page called “blog” and wanted to fetch all the images contained in the child pages of that page. Then this bit of code would grab all images from all posts:

In my blog.php I could do this:

$images = $page->children()->files()->filterBy('type', 'image');
foreach($images as $image) {
  echo $image->url();

So this would, of course, just give me a silly list of image URLs, but good for testing. I suggest you try this first before using the plugin to see if the code works.

hey @texnixe ended up using this and it seemed to work. Thanks again for your help.

 $journalPage = $pages->find('journal');
   $images = $journalPage->children()->files()->filterBy('type', 'image');
echo guggenheim($images, array('width' => 1200, 'height' => 350, 'border' => 8));

Glad that it works now.

Instead of $pages->find('journal') you can also use the page helper

$journalPage = page('journal');
1 Like