Jump to content

Recommended Posts

Posted

I'm creating a site that has a huge image gallery. I'm using the api to pull out randomised images from the gallery and display them on the home page. However, the client doesn't like all the images that are I'm the gallery. So I was wondering if there was a way could add an extra field property the the image to mark is as a favourite. Is this possible?

Posted

That sounds ideal. How do I access that property from the api please? I'm having trouble accessing other parts of the pw site to research ATM.

Posted

I think you are referring to the tags property?

$page->images->first()->tags

or 

$page->images->eq(n)->tags

where n is the number of the image in the images field starting with 0

Posted

First day back today and i'm not as quick as desired with the api, I've tried this:

$randogals =$pages->find("template=gallery-album");
$randogal = $randogals->getRandom();
$randomimg = $randogal->images->first()->tags->size($thumbWidth, $thumbHeight);

but that produced me a 500 error.

What i'm trying to get is a random gallery with a random image where in each instance the tag contains the text 'fav'.

Posted

I'm guessing "tags" here is something you'd need to be testing for. 

$randomimg = $randogal->images->find("tags=fave")->first();

Haven't actually used them recently so not 100% sure.

  • Like 1
Posted

got there at last like this:

$randogals =$pages->find("images.tags=fav");
$randogal = $randogals->getRandom();
$randomimgarray = $randogal->images->findTag('fav');
$randomimg = $randomimgarray->getRandom()->size($thumbWidth, $thumbHeight);

$randogal2 = $randogals->getRandom();
$randomimgarray2 = $randogal2->images->findTag('fav');
$randomimg2 = $randomimgarray2->getRandom()->size($thumbWidth, $thumbHeight);

I actually display two favourite images on the same page. I wonder if anyone can think of a simple tidy way to ensure that the same image isn't used twice on the same page at the same time?

Posted

You can do it in one with findRandom(2) and then you won't need to worry about duplicate images:

$randogals =$pages->find("images.tags=fav");
$randogal = $randogals->getRandom();
$randomimgarray = $randogal->images->findTag('fav');
foreach($randomimgarray->findRandom(2) as $randomimage){
    echo $randomimage->size($thumbWidth, $thumbHeight); 
}
  • Like 1

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...