0

Following on from here: Output x twice then y, then x twice

I have two lists. (E) is full of entries from multiple channels. (T) is a collection of tweets from another channel.

On each page there needs to be 1 tweet and 5 entries.

The output order needs to be (E) (E) (T) (E) (E) (E)

The output order has been resolved using the @Romans-8---31-39 method.

I am using ajax to load in the next set of entries/tweets and appended onto the bottom of the list.

It's nearly all working, except for the tweets. As the url for loading the next set of entries is P5, it is returning every 5th tweet. I've tried using a negative offset on the get tweet list call, but to no prevail.

Here is the code (just the core stuff here)

{!--set main multi-channel entry list--}
{exp:stash:set_list name="posts"  parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="events|projects|stories|voices" dynamic="no" disable="categories|member_data" paginate="bottom" limit="5" orderby="date" sort="desc"} 
      {stash:title}{title}{/stash:title}
      {!-- create the pagination links --}
            {paginate}
        {exp:stash:set_list:nested name="pagination"}
            {stash:current_page}{current_page}{/stash:current_page}
          {pagination_links}
            {next_page}{stash:next_page}{pagination_url}{/stash:next_page}{/next_page}
          {/pagination_links}
        {/exp:stash:set_list:nested}
        {/paginate}
    {/exp:channel:entries}
{/exp:stash:set_list}

{!--set tweet list--}
{exp:stash:set_list name="tweets" parse_tags="yes" parse_depth="3"}
    {exp:channel:entries channel="tweets" dynamic="no" disable="categories|member_data" limit="1" paginate="bottom" orderby="date" sort="desc"} 
        {stash:tweet}{tweet}{/stash:tweet}
        {!--set a number to match every third count where the tweet should be output--}
        {stash:two_count}{exp:math formula="{count} * 3"}{/stash:two_count}
        {stash:two_count_next}{exp:math formula="{count} * 4"}{/stash:two_count_next}
    {/exp:channel:entries}
        {paginate}
      {exp:stash:set_list:nested name="pagination_t"}
        {pagination_links}
            {stash:current_page}{current_page}{/stash:current_page}
          {next_page}{stash:next_page}{pagination_url}{/stash:next_page}{/next_page}
        {/pagination_links}
      {/exp:stash:set_list:nested}
    {/paginate}
{/exp:stash:set_list}


{!--output multi-channel list and tweet list--}
<div class="ajax-wrapper">
    {exp:stash:get_list name="posts" prefix="st1"}
        {!-- PAGINATED PAGE --}
        {!-- check to see what page we are on, slightly different layout used --}
        {exp:switchee variable="{segment_1}" parse="inward"}
            {case value="#^P(\d+)$#"}
                {!--output tweet on every forth loop--}
                {if st1:count % 4 == 0}
                            {!-- get the tweet --}
                    {exp:stash:get_list:nested name="tweets" match="#{st1:count}#" limit="1" against="two_count_next" prefix="st2"}
                        {!--if no results, output main channel entry--}
                        {!-- image left / text right --}
                        {if st2:no_results}
                            {st1:title}
                        {/if}
                        {!--tweet--}
                            {st2:tweet}
                        {!--3rd main--}
                        {!-- image left / text right --}
                        {st1:title}
                    {/exp:stash:get_list:nested}
                {!--otherwise output main channel entry--}
                {if:else}
                    {st1:title}
                {/if}                       
            {/case}

            {!-- FIRST PAGE, slightly different layout used --}
            {case default="true"}
               {!--output tweet on every third loop--}
            {if st1:count % 3 == 0}
                {exp:stash:get_list:nested name="tweets" limit="1" match="#{st1:count}#" against="two_count" prefix="st2"}
                    {st2:tweet}
                {/exp:stash:get_list:nested}
              {!--3rd main--}
                        {st1:title}
                {!--otherwise output main channel entry--}
            {if:else}
                    {st1:title}
            {/if}
            {/case}
        {/exp:switchee}  

    {/exp:stash:get_list}
    {exp:stash:get_list name="pagination"}
        {if next_page}<a href="{next_page}" class="pager-link js-pagination">Next</a>{/if}
        {exp:stash:set name="current_page"}{current_page}{/exp:stash:set}
    {/exp:stash:get_list}
</div>

1 Answer 1

1

Solved!

On the subsequent pages I'm using a normal entries loop, and using stash and a math plugin to calculate the offset

{exp:stash:get_list name="pagination"}
     {exp:stash:set name="current_page"}{exp:math formula='{current_page} - 1'}{/exp:stash:set}
{/exp:stash:get_list}

then:

{exp:channel:entries channel="tweets" parse="inward" dynamic="off" disable="categories|member_data" offset="{exp:stash:current_page}" limit="1"  paginate="bottom" orderby="date" sort="desc"} 
  {tweet}
{/exp:channel:entries}
1
  • 1
    Congrats on finding a solution! Commented Apr 7, 2015 at 17:01

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.