Jump to content

Image custom fields as selectors


Rossie
 Share

Recommended Posts

Hi Everyone,

I wish to display a gallery of images from multiple pages on the site.  These images have custom fields created through page reference called 'furniture_list_type'.  Each image now has a radio button which has been selected.

In  the example code below all images appear from the "gallery20", however the selector  "gallery20.furniture_list_type=3390" does not have any effect.  "3390" is the id of the page reference "chair" selected through the page reference.  I wish only images selected as chair to show.

Hope someone can help with this.

 

Thanks,

 

Calum

 

$imagePages = $pages->find("template=makers-child, gallery20.furniture_list_type=3390") ;  
            
    

foreach($imagePages as $p) {

    echo "<ul>";

    foreach($p->gallery20 as $image) {

        echo "<li><img src='{$image->url}'>{$image->furniture_list_type}</li>";

    }

    echo "</ul>";

    
}
Link to comment
Share on other sites

Welcome to the PW forums @Rossie!

This part...

8 hours ago, Rossie said:

$imagePages = $pages->find("template=makers-child, gallery20.furniture_list_type=3390") ;

...finds all the pages that contain at least one image in the gallery20 field that has furniture_list_type=3390 in the image's custom fields.

But those pages can also contain images that don't have furniture_list_type=3390 in their custom fields. So if you only want to output certain images from the gallery20 field you need to use a WireArray find() selector to get those images.

Your code would look something like this:

// Find the pages that have at least one image in the gallery20 field with furniture_list_type=3390
$imagePages = $pages->find("template=makers-child, gallery20.furniture_list_type=3390") ;

// For each of those pages...
foreach($imagePages as $p) {
	// Find the images in the gallery20 field with furniture_list_type=3390
	$chair_images = $p->gallery20->find("furniture_list_type=3390");
	echo "<ul>";
	// Loop over the chair images
	foreach($chair_images as $image) {
		echo "<li><img src='{$image->url}'>{$image->furniture_list_type}</li>";
	}
	echo "</ul>";
}

 

  • 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

×
×
  • Create New...