2

I need to merge to loops into one stash list.

The first loop is a standard channel entries loop. The second is a twitter time line, using CE Twitter.(http://www.causingeffect.com/software/expressionengine/ce-tweet)

Here is my code thus far, I've removed a lot of the markup and variables et al...

{!-- set list --}
{exp:stash:set_list name='journal_list' parse_tags='yes' depth="2" parse="inward"}

    {exp:channel:entries channel="journal" dynamic="no" paginate="bottom" sort="desc" limit="10"} 
        {!-- append to the list the channel entries --}
        {exp:stash:append_list name='journal_list' parse_tags='yes' depth="2" parse="inward"}
                {!--type set as post, used to output post markup --}
                {stash:type}post{/stash:type}
                {!-- entry date saved to variable - the idea is to then use this as the order by argument --}
                {stash:entry_date}{entry_date}{/stash:entry_date}
                {!-- All the usual gubbins, titles, images, text et all, all sorted in stash variables --}
        {/exp:stash:append_list}

    {/exp:channel:entries} 

    {exp:ce_tweet:user_timeline screen_name="myMegaTwitterAccount" count="5" sort="asc"}
        {!-- append to the same list as above for the twitter time line --}
        {exp:stash:append_list name='journal_list' parse_tags='yes' depth="2" parse="inward"}
                {!--type set as tweet, used to output tweet markup --}
                {stash:type}tweet{/stash:type}
                {!-- entry date saved to variable - the idea is to then use this as the order by argument --}
                {stash:entry_date}{created_at}{/stash:entry_date}
        {/exp:stash:append_list}

    {/exp:ce_tweet:user_timeline}

{/exp:stash:set_list}


{exp:stash:get_list name='journal_list' order_by="{entry_date}" paginate="bottom" limit="5"}
    {if "{type}" == "Post"}
        {!-- all the post markup here --}
  {if:else}
    {!-- all the tweet markup here --}
  {/if}
{/exp:stash:get_list}

The code above works, but not quite right.

Currently the two lists are outputted separately, i.e. first all of the channel entries are outputted, then all the tweets.

What I need is for the sort order to be based solely on the {entry_date}, so the tweets and posts will be mixed up... [post post tweet post tweet post post] etc etc

I'm sure this will be possible, I may have approached this incorrectly. Fairly new to stash, although I have to say I'm bloomin' loving it (Thanks Mark!)

I've added a screenshot below which should illustrate the issue I have, notice the dates on the items. eeee! (n.b using masonry for the layout)

Any help, greatly appreciated

enter image description here

  • I would think a good place to start would be comparing the format of the two (different) fields you are using for {stash:entry_date} - your approach relies upon these being similarly scaled numbers, but if this assumption is not true (silly example, but if each was using a different year for the date) it would explain why they are being output in the order you see. Might be worth doing a quick test that just lists out the title and date (in order) to see if dates are indeed of the same type... – JCOGS Design Feb 6 '17 at 19:33
1

You should be able to do this by setting a list with the channel entry output and just appending the tweet module output to that list. A couple of other things, you have depth of 2 which adds processing and shouldn't be necessary in this case. (this is untested):

{!-- set list --}
{exp:stash:set_list 
    name='journal_list' 
    parse_tags='yes' 
    parse="inward"
}
    {exp:channel:entries channel="journal" dynamic="no" paginate="bottom" sort="desc" limit="10"} 
        {stash:type}post{/stash:type}
        {stash:entry_date}{entry_date}{/stash:entry_date}
    {/exp:channel:entries} 
{/exp:stash:set_list}

{exp:ce_tweet:user_timeline screen_name="myMegaTwitterAccount" count="5" sort="asc"}
    {!-- append to the same list as above for the twitter time line --}
    {exp:stash:append_list 
        name='journal_list' 
        parse_tags='yes' 
    }
        {stash:type}tweet{/stash:type}
        {stash:entry_date}{created_at_relative}{/stash:entry_date}
    {/exp:stash:append_list}
{/exp:ce_tweet:user_timeline}

{!--output the list--}
{exp:stash:get_list 
    name='journal_list' 
    order_by="{entry_date}" 
    paginate="bottom" 
    limit="5"
    process="end"
}
    {if "{type}" == "Post"}
        {!-- all the post markup here --}
    {if:else}
        {!-- all the tweet markup here --}
    {/if}
{/exp:stash:get_list}

I added a process=end to the get_list, but depending on how you have the templates set up you may not need that. Also, the ce_tweet module tag may need to be wrapped with stash:parse so that it runs after the initial set_list. If that's the case, you would use:

{exp:stash:parse process="inline" parse_depth="2"}
    {exp:ce_tweet:user_timeline screen_name="myMegaTwitterAccount" count="5" sort="asc"}
        {!-- append to the same list as above for the twitter time line --}
        {exp:stash:append_list 
            name='journal_list' 
            parse_tags='yes' 
        }
            {stash:type}tweet{/stash:type}
            {stash:entry_date}{created_at_relative}{/stash:entry_date}
        {/exp:stash:append_list}
    {/exp:ce_tweet:user_timeline}
{/exp:stash:parse}
| improve this answer | |
  • Thanks, I'll take a look at this over the weekend. Appreciated – magicspon Aug 8 '14 at 16:44
  • Hello, (been away for a while)... Still no joy with this... All the journal items are outputted, then the tweets. Rather than being spat out in date order. Any thoughts – magicspon Sep 15 '14 at 21:47

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.