I have a tutorials section on my website, and I’m using relationships to group multiple-page tutorials together. There is a relationships field on the “parent” tutorial where I select the “child” tutorials that belong to that parent - in reality they’re all entries in the tutorial channel.
On a child tutorial page (uses the same template as the parent, there is a flag set to “Yes” on the parent) I want to show Next and Previous links, taking them to the next and previous sibling for that particular parent.
I thought the “siblings” tag would accomplish what I need - have two sibling tags, one for each previous and next link. The previous link would order by descending, stop before the publish date of the current tutorial page while the next link would order by ascending and start after the publish date of the current tutorial page. Both tags would be “1”.
This works when I hard-code the entry date, however I can’t get it working dynamically.
This is my hard-coded version, which works (on page 2, it displays page 1 for previous and page 3 for next):
{if:elseif tutorial_top_level == 'No'}
<div class="row">
{siblings field="tutorial_children" limit="1" stop_before="2014-12-15 21:24"}
<div class="col-xs-12 col-sm-6">
<a href="http://{siblings:url_title_path=%27tutorials/article%27}" class="tags__link">« {siblings:title}</a>
</div>
{/siblings}
{siblings field="tutorial_children" limit="1" start_on="2014-12-15 21:24"}
<div class="col-xs-12 col-sm-6">
<a href="http://{siblings:url_title_path=%27tutorials/article%27}" class="tags__link">{siblings:title} »</a>
</div>
{/siblings}
</div>
{/if}
However if I then try and change the “stop_before” and “start_on” dates to be dynamic, the sibling tag is then printed to the browser and “page 1” is shown for the tag (see attachment):
{siblings field="tutorial_children" limit="1" stop_before="{entry_date format='%Y-%m-%d %H:%i'}"}
For now I’m going to try using raw PHP to print the sibling tag with a hard-coded date to see if it works any better, but I thought I’d raise this in case I’m doing something stupid!
I managed to get this working without PHP by using an embedded template, passing in the entry_id and entry_date (pre-formatted) parameters - as shown below:
{exp:channel:entries channel="tutorials" entry_id="{embed:entry_id}"}
{siblings field="tutorial_children" limit="1" orderby="entry_date" sort="desc" stop_before="{embed:entry_date}"}
...
{/siblings}
{siblings field="tutorial_children" limit="1" orderby="entry_date" sort="asc" start_on="{embed:entry_date}"}
...
{/siblings}
{/exp:channel:entries}
In my original template:
{embed='...' entry_id="{entry_id}" entry_date="{entry_date format='%Y-%m-%d %H:%i'}"}
I can’t see the logic behind why this wouldn’t work in the same template though?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.