Jump to content

Next/previous links excluding pages based on options field


alexcapes
 Share

Recommended Posts

Hi all,

I have the following simple code for next/previous links on article pages:

<!-- Next article -->
<?if($page->next->id) { ?><i class="icon-chevron-left"></i> <a href="<?echo $page->next->url; ?>"> <?=${'previous_'.$countryCode}; ?></a><? } ?>
<!-- /Next article -->

<!-- Previous article -->
<?if($page->prev->id) { ?> <a href="<?echo $page->prev->url; ?>"><?=${'next_'.$countryCode}; ?></a> <i class="icon-chevron-right"></i> <? } ?>
<!-- /Previous article -->

It all works correctly but there's a certain type of article I need to exclude from the next/previous links (any page that has options field 'content_type' with a value of '6').

I'm trying to figure out a way to get 'next' and 'previous' but if 'content_type' on that page has a value of '6' then skip it.

Can anyone help with some clues on how this might be done? I've had a look at using the pagination code as well as looking at grabbing 'siblings' and filtering them but come to a dead end.

Thanks!

Link to comment
Share on other sites

$list = $page->siblings("content_type!=6");

$list->getPrev($page);
$list->getNext($page);

Wonderfully simple solution - thank you LostKobrakai!

For anyone interested this was my final code - all working correctly:

$list = $page->siblings("content_type!=6,sort=article_publish_date");

$prevPage = $list->getPrev($page);
$nextPage = $list->getNext($page);

if($prevPage) echo "<i class='icon-chevron-left'></i> <a href='{$prevPage->url}'>" . ${'previous_'.$countryCode} . "</a>";
if($nextPage) echo "<a href='{$nextPage->url}'>" . ${'next_'.$countryCode} . "</a> <i class='icon-chevron-right'></i>";

  • Like 1
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

×
×
  • Create New...