Alessio Dal Bianco Posted September 2, 2013 Share Posted September 2, 2013 Hi all, i found a problem regarding filtering items. For example i limit the number of images (4) in this way: <?php if( count($page->images) ) foreach( $page->images->filter("limit=4") as $seoImg ): ?> <meta property="og:image" content="<?php echo "http://".$config->httpHost.$seoImg->size(300,300)->url ?>" /> <?php endforeach; ?> More later in the template i create the main gallery with ALL images (about 10 images): <?php foreach( $page->images as $img ): ?> <li> <div class="text" style="background-image:url(<?php echo $img->width(80)->url ?>)"> <?php echo $img->description; ?> </div> </li> <?php endforeach; ?> But when i call "$page->images" it returns me only 4 items, same behavior with "slice(0,4)". I've tried also with "$page->get('images')" with the hope that in this way i can override the filter... But nothing, it seems that the results of filters override the original results in the property. Link to comment Share on other sites More sharing options...
diogo Posted September 2, 2013 Share Posted September 2, 2013 Alessio, that's the intended behavior of filter. It changes your wireArray forever Use find() instead on your first foreach. $page->images->find("limit=4") 2 Link to comment Share on other sites More sharing options...
Alessio Dal Bianco Posted September 2, 2013 Author Share Posted September 2, 2013 my fault. Also slice works as expected, because when i was trying there was another same filter below for other meta tags! Thank you diogo! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now