renobird Posted June 27, 2012 Share Posted June 27, 2012 Hello all, How can I access the first image on the prev/next pages? I'm trying to use a thumbnail of an image from the prev/next pages to create a simple nav. I was hoping this would work: $nextThumb = $page->next->images->first()->size(75,75); echo "<a href='{$page->next->url}'><img src='$nextThumb->url' /></a>";} But I get.... Error Call To A Member Function First() On A Non-Object Link to comment Share on other sites More sharing options...
apeisa Posted June 27, 2012 Share Posted June 27, 2012 On mobile, but shouldn't there be next() with those parenthesis? Link to comment Share on other sites More sharing options...
apeisa Posted June 27, 2012 Share Posted June 27, 2012 Hmm.. looking at the API I guess both should work. Other possible failures: You are on last sibling, so next will return a nullpage => therefore no images Your images are configured to have only 1 image, so first() is already assumed Link to comment Share on other sites More sharing options...
renobird Posted June 27, 2012 Author Share Posted June 27, 2012 OK, False alarm. The error was because the next/prev pages don't contain the images — it's the children of the next/prev pages that have the images field. I forgot I moved the image to the child pages (been on this project too long.) Apeisa, forced me at gunpoint to come here and confess my sins. As you were... 1 Link to comment Share on other sites More sharing options...
renobird Posted June 28, 2012 Author Share Posted June 28, 2012 Just thought I report back with an actual working method for this scenario. I needed to get the title of the next page (category) and create a thumbnail for that category using an image from the first project in that category. our-work - category1 - project1 (need first image from here) - project2 - project3 - category2 - project1 (need first image from here) - project2 - project3 if ($page->prev->id) { $prevThumb = $page->prev()->child()->images->first()->size(100,100); echo "<a href='{$page->prev->url}'><img src='{$prev->url}' /><br />{$page->prev->title}</a>"; } if ($page->next->id) { $nextThumb = $page->next()->child()->images->first()->size(100,100); echo "<a href='{$page->next->url}'><img src='{$next->url}' /><br />{$page->next->title}</a>"; } 4 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