3

I have been stuck on this one for a few days now:

Page Content:

Main blog post (current entry) + a sidebar displaying the previous 3 blog entries

Sidebar Code:

{exp:channel:entries channel="blog" status="open" limit="3" orderby="date" sort="desc" dynamic="off" url_title="not {last_segment}"}
                <!-- NEWS BOX # -->
                <div class="col-sm-4 text-center">

                    <img src="{blog_image}" class="project-img" />
                    <h4><strong><a href="{url_title_path='blog'}">{blog_title}</a></strong></h4>
                    {blog_description}

                </div>
                <!-- NEWS BOX # -->
 {/exp:channel:entries}

Goal:

Regardless of the current blog being viewed, the sidebar should always display 3 previous entries posted prior to the 'viewed' blog entry date.

As an example:

  • Blog 1 - Entry Date: 2017-03-06
  • Blog 2 - Entry Date: 2017-03-05
  • Blog 3 - Entry Date: 2017-03-04
  • Blog 4 - Entry Date: 2017-03-03
  • Blog 5 - Entry Date: 2017-03-02
  • Blog 6 - Entry Date: 2017-03-01

If Blog 2 is the current entry in view, the sidebar would show Blog 3, Blog 4 and Blog 5

If Blog 3 is the current entry in view, the sidebar would show Blog 4, Blog 5 and Blog 6

If Blog 5 is the current entry in view, the sidebar would show Blog 6

Any help offered is appreciated.

1 Answer 1

4

my guess would be you'll need an embed. the in the main template (within the channel:entries tag) call that embed something like this:

{exp:channel:entries}
{embed="_inc/_previous_three_posts" the_start_date="{entry_date}" the_entry_id="{entry_id}"}
{/exp:channel:entries}

Your embed would look something like this:

{exp:channel:entries start_on="{embed:the_start_date}" limit="3" entry_id="not {embed:the_entry_id}" dynamic="no"}
{title}
{/exp:channel:entries}
1
  • Thanks for pointing me in the right direction. Minor tweak to your suggestion to show the previous 3 entries, changed start_on to stop_before and added orderby and sort. Updated as follows: {exp:channel:entries stop_before="{embed:the_start_date}" limit="3" entry_id="not {embed:the_entry_id}" orderby="date" sort="desc" dynamic="no"} Commented Mar 15, 2017 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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