Marty Walker Posted April 30, 2012 Share Posted April 30, 2012 Hi, I'm setting up some next/prev page linking code. I only want those links to show if the page's publish_date field is less than today. Here's my convoluted and cobbled-together code: <?php $today = time(); if($page->prev->getUnformatted('publish_date')<$today) echo "<li id='prev'><a rel='nofollow' title='{$page->prev->title}' href='{$page->prev->url}'>{$page->prev->title}</a></li>"; if($page->next->getUnformatted('publish_date')<$today) echo "<li id='next'><a rel='nofollow' title='{$page->next->title}' href='{$page->next->url}'>{$page->next->title}</a></li>"; Firstly, is there a way to simplify this? Secondly, if there's no value returned for the previous page (for example) it still outputs the HMTL. ie: <li id='prev'><a rel='nofollow' title='' href=''></a></li> Thanks for any help. Cheers Marty Link to comment Share on other sites More sharing options...
diogo Posted April 30, 2012 Share Posted April 30, 2012 if there's no value returned for the previous page (for example) it still outputs the HMTL this happens because 0 is less than today. You have to test also for it's existence. "less than today AND more than 0" for example. Link to comment Share on other sites More sharing options...
Marty Walker Posted April 30, 2012 Author Share Posted April 30, 2012 Thanks diogo. This is what I ended up with which works fine: <?php $today = time(); if($page->prev->getUnformatted('publish_date')<$today && $page->prev->id > 0) echo "<li id='prev'><a rel='nofollow' title='{$page->prev->title}' href='{$page->prev->url}'>{$page->prev->title}</a></li>\n"; if($page->next->getUnformatted('publish_date')<$today && $page->next->id > 0) echo "<li id='next'><a rel='nofollow' title='{$page->next->title}' href='{$page->next->url}'>{$page->next->title}</a></li>"; Regards Marty Link to comment Share on other sites More sharing options...
ryan Posted April 30, 2012 Share Posted April 30, 2012 Here's another way you could go: $siblings = $page->siblings('publish_date<' . time()); if(($prev = $page->prev($siblings)) && $prev->id) echo "..."; if(($next = $page->next($siblings)) && $next->id) echo "..."; 2 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