n00dles101 Posted February 8, 2011 Share Posted February 8, 2011 Hi, Quick one I hope. having a hard time understanding how Images work. How do I return the first image in the images array ? rgds, Mike. Link to comment Share on other sites More sharing options...
ryan Posted February 8, 2011 Share Posted February 8, 2011 Mike, For this example, I'll assume your field is called "images". To get the first image, you would do this: $firstImage = $page->images->first(); To get a numbered index, you would do: $nthImage = $page->images->eq($n); // where $n is a 0-based index Or, of course you can iterate the images too: $n = 0; foreach($page->images as $image) { echo "Image $n - " . $image->url; $n++; } 2 Link to comment Share on other sites More sharing options...
ryan Posted February 8, 2011 Share Posted February 8, 2011 Also see: /wire/core/Array.php There are lots of different methods in there, most based on jQuery traversal methods. This class is the basis for almost all ProcessWire arrays, including images. I use it for reference all the time. But I am working on getting an online reference for this class and others. Link to comment Share on other sites More sharing options...
n00dles101 Posted February 8, 2011 Author Share Posted February 8, 2011 wow.. that was quick.. knew it was going to be something simple... and you seem to have covered every base here... Thanks for your help.. Mike. Link to comment Share on other sites More sharing options...
modifiedcontent Posted August 8, 2018 Share Posted August 8, 2018 Is there a way to get the last image? I thought last() worked, but it seems it doesn't. Link to comment Share on other sites More sharing options...
adrian Posted August 8, 2018 Share Posted August 8, 2018 1 hour ago, modifiedcontent said: Is there a way to get the last image? I thought last() worked, but it seems it doesn't. That should work just fine: 1 Link to comment Share on other sites More sharing options...
Krlos Posted August 8, 2018 Share Posted August 8, 2018 15 minutes ago, adrian said: That should work just fine: Hey @adrian, what is that Console window? looks really usefull 1 Link to comment Share on other sites More sharing options...
adrian Posted August 8, 2018 Share Posted August 8, 2018 1 minute ago, Krlos said: Hey @adrian, what is that Console window? looks really usefull TracyDebugger's Console Panel - https://adrianbj.github.io/TracyDebugger/#/debug-bar?id=console 3 1 Link to comment Share on other sites More sharing options...
cstevensjr Posted August 8, 2018 Share Posted August 8, 2018 6 hours ago, adrian said: TracyDebugger's Console Panel - https://adrianbj.github.io/TracyDebugger/#/debug-bar?id=console Wow, @adrian! I had no idea that you have taken time to create some nice documentation for your module. Great work! 5 Link to comment Share on other sites More sharing options...
adrian Posted August 8, 2018 Share Posted August 8, 2018 Just now, cstevensjr said: Great work! Thanks ? It's a decent start, but I am kinda hoping for some contributions from the community for improving it. It's all available in the docs folder (markdown files) in the repo and anyone can edit and submit PRs. I think a nice Tips & Tricks section would be beneficial, as would improvements to the rest of the docs. 3 1 Link to comment Share on other sites More sharing options...
modifiedcontent Posted August 9, 2018 Share Posted August 9, 2018 18 hours ago, adrian said: That should work just fine: ... My last image was a cropped version of the first, saved as copy. I only had two images. When I duplicated the cropped image, making it the last of three images, last() did pick it up. Variations of an image don't count for first/last etc.? I'll keep testing if this consistently happens or if I just had a cache issue or something else. Link to comment Share on other sites More sharing options...
gmclelland Posted August 9, 2018 Share Posted August 9, 2018 @modifiedcontent Maybe this is similar to and this issue https://github.com/processwire/processwire-issues/issues/650 which was recently fixed at https://github.com/processwire/processwire/commit/a1676b0adb3bb7877d0602e1ab1929fd5aff73d4 You might need to download and update Processwire to the latest dev commit? Hope that helps 2 1 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