Jump to content

How do I work with the NullPage with $page->prev and $page->next?


ljones
 Share

Recommended Posts

I have read over the API and am stumped on how to do this.

I don't want a "previous" or "next" graphic to show up when there is a null page on either end.

Obviously this code will not work

$page->prev->url->NullPage  [or maybe sibling->first() or ->last()]?

and does not function, but it gives an idea of what I am trying to do:

<?php
echo "<div class='gallery-detail-nav'>";

if ($page->prev->url->NullPage) echo "<a href='{$page->prev->url}'><img src='{$config->urls->templates}stylesheets/images/null.jpg' /></a>";
else echo "<img src='{$config->urls->templates}stylesheets/images/back.jpg' /></a>";

echo "<a href='{$page->parent->url}'><img src='{$config->urls->templates}stylesheets/images/thumbs.jpg' /></a>";

if ($page->next->url->NullPage) echo "<img src='{$config->urls->templates}stylesheets/images/null.jpg' /></a>";
else echo "<a href='{$page->next->url}'><img src='{$config->urls->templates}stylesheets/images/next.jpg' /></a>";
echo "</div>";

I would also like to figure out how to cycle in a circle, if possible.

Link to comment
Share on other sites

Added <?php to your code example.

I have not used prev and next, but this should work:

<?php
if ($page->prev->id) {
  echo "prevlink here";
}

There is this note in documents to be aware of:

†The siblings, next and prev properties and methods may not be efficient to use when the page has a lot of siblings. Care should be taken on large sites in consideration of the fact that these properties will load all sibling pages. In large scale use, you should make use of the function/method equivalent versions: siblings($selector), next($pageArray), and prev($pageArray), so that you can control the number of pages loaded.

But if you want to do a full circle, I assume that you don't have too many pages. To make a circle, this could work:

<?php

if ($page->next->id) {
  echo "nextlink";
} else {
  $firstpage = $page->siblings->first();
  echo "<a href='$firstpage->url'>$firstpage->title</a>";
}
Link to comment
Share on other sites

Thanks Apesia,

I decided to use the full circle code. I was able to tweak it so that I can circle backwards as well. It works just like this site I built in Wordpress using a very nice, but bulky plugin that required a lot of hacking. http://lopemaxdiaz.com/paintings/image-7-la-colora

There will be fewer that 40 sibling pages per parent, so I don't think that will be too much of a load.

Thanks again!

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