Jump to content

Gallery not working


howsoonisnow90
 Share

Recommended Posts

hey guys, I'm new here. ?
I'm building this gallery of images but I don't know how to show it. 

I've created a field in my page called 'VIAGGI_gallery', image type, and I can load all the images related to that page. 
The problem occurs when I try to print the pictures, like this:

echo $page->get('VIAGGI_gallery');

it basically gives me the names of the pictures, eg - hawaii_1.jpg, hawaii_2.jpg ecc. 

How can I print all my pictures? I guess I'm working with an object? should I use a cycle? 

thanks a lot!!

Link to comment
Share on other sites

Hi @howsoonisnow90. Welcome to ProcessWire and the forums ?.

50 minutes ago, howsoonisnow90 said:

'VIAGGI_gallery',

Not directly related to your question, but you will want to rename your field. ProcessWire uses and prefers lowercase letters for field names. So, viaggi_gallery.

50 minutes ago, howsoonisnow90 said:

I guess I'm working with an object? should I use a cycle? 

Yes and yes. Your viaggi_gallery field is most likely an image field that accepts and outputs multiple images. So, when you do an echo $pages->get('your_field') you are actually telling ProcessWire to output a whole collection of images and it is asking you which one? There are a number of images in here. Secondly, you need to specify what property of the object you want it to out. Maybe an object->url, or object->description, etc. 

50 minutes ago, howsoonisnow90 said:

it basically gives me the names of the pictures, eg - hawaii_1.jpg, hawaii_2.jpg ecc. 

This is just a toString() method kicking in. 

50 minutes ago, howsoonisnow90 said:

How can I print all my pictures?

<?php namespace ProcessWire;

$out = "";
// ---------
$out .= "<ul>";
foreach($page->viaggi_gallery as $image){
  // foreach($page->get('viaggi_gallery') as $image){// would also work
  // most likely you want a thumb so create one
  //  processwire will only create this if one is not already available
  // $thumb = $image->size(200,200);
  // if you want to specify height only and let width be automatically determined
  $thumb = $image->height(200);
  $out .= "<li><a href='{$image->url}'><img src="{$thumb->url}" alt="{$image->description}"></a></li>";
}
// -----
$out .= "</ul>";
echo $out;

Have a look the documentation and the getting started tutorials.

https://processwire.com/api/ref/pageimages/

https://processwire.com/api/ref/pageimage/

https://processwire.com/docs/tutorials/

 

ps: written in browser; please check for errors.

Edited by kongondo
added more
  • Like 1
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...