I have a channel called "course_content" that contains a relationship field which holds entries from a "lesson_content" channel.

The user clicks on a course (course_content) and all of the lessons related to that course are displayed. They then select the lesson that they want to view.

I'm trying to add "Previous" and "Next" links to the lesson entry pages to allow the user to navigate the lessons specific to that course. Currently, I'm using the following code:

{exp:channel:prev_entry channel="lesson_content"}

    <a class="older" href="{path=courses/lesson}"><span><i class="icon-left"></i> Previous</span></a>


{exp:channel:next_entry channel="lesson_content"}

    <a class="newer" href="{path=courses/lesson}"><span>Next <i class="icon-right"></i></span></a>


The problem is that is is looping through the entire "lesson_content" channel so when you get to the end of the lessons for that class, you continue to lessons from the next class.

I'm sure I need to use an embed, I just can't figure out how to specify just the entries that are found in the same relationship as the entry that is being viewed.

Any help would be appreciated.


I don't think you need an embed - have you tried the siblings tags?


Someone has posted a potential solution here: https://expressionengine.com/forums/topic/247219/siblings-tag-cant-handle-dynamic-parameters

To summarise here (untested):

{exp:channel:entries channel="lesson_content"}
  {siblings limit="1" orderby="entry_date" sort="desc" stop_before="{entry_date}"}
    <a href="{siblings:url_title_path=courses}">{siblings:title}</a>
  {siblings limit="1" orderby="entry_date" sort="asc" start_on="{entry_date}"}
    <a href="{siblings:url_title_path=courses}">{siblings:title}</a>
  • Thanks James. That code, along with the link to the EE Forum post got it working for me. I always forget about the EE Forums. :-( I'm going to post my code as an answer. – Brad Hopkins Jan 5 '18 at 18:07

I ended up using an embed to accomplish this.

Embed Code - based on the EE Forum link: https://expressionengine.com/forums/topic/247219/siblings-tag-cant-handle-dynamic-parameters

{embed="courses/lesson-pagination" entry_id="{entry_id}" entry_date="{entry_date format='%Y-%m-%d %H:%i'}"}

Embed Template

{exp:channel:entries channel="lesson_content"}
              {siblings limit="1" orderby="entry_date" sort="desc" stop_before="{embed:entry_date}"}
                <span class="navigate previous"><a href="{siblings:url_title_path=courses/lesson}"><i class="icon-left"></i> Previous</a></span>

              {siblings limit="1" orderby="entry_date" sort="asc" start_on="{embed:entry_date}"}
                <span class="navigate next"><a href="{siblings:url_title_path=courses/lesson}">Next <i class="icon-right"></i></a></span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.