Jump to content

Prev/Next Page Thumbnails


renobird
 Share

Recommended Posts

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

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

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

:P

  • Like 1
Link to comment
Share on other sites

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>";
}
  • Like 4
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...