3

Excuse the title, couldn't really summarise the issue succinctly...

This is what I need to do...

I have a load of entries from various channels (E). And a series of tweets (T) (which are stored in another channel).

I need to output as follows

(E) (E) (T) (E) (E) (T)...

(also, if T doesn't exist output E).

So every third item that is outputted needs to come from the twitter channel.

I'm using stash but can't for the life of me figure out how to output the content like this.

Any thoughts/suggestions greatly appreciated.

Thanks Dave

Follow on question Paginate two stash lists in one

2
  • One possible solution would be to just output (E)'s and (T)'s, giving them css classes to distinguish them, and then use jQuery to weave the (T)'s in among the (E)'s. Are you using jQuery in this project? Commented Mar 31, 2015 at 21:43
  • Hello, thanks for your reply. However I don't think using jquery is a suitable solution.
    – magicspon
    Commented Apr 2, 2015 at 10:08

2 Answers 2

2

This builds on CreateSean's answer, since you're using Stash. You'll need a math plugin and in this example I'm using Math from Caddis.

{!--set main multi-channel entry list--}
{exp:stash:set_list
    name="one" 
    parse_tags="yes"
}
    {exp:channel:entries
        channel="ONE_CHANNEL|ANOTHER_CHANNEL|ETC"
        dynamic="no"
    } 
        {stash:entry_id}{entry_id}{/stash:entry_id}
        {stash:title}{title}{/stash:title}
    {/exp:channel:entries}
{/exp:stash:set_list}

{!--set tweet list--}
{exp:stash:set_list
    name="two" 
    parse_tags="yes"
    parse_depth="2" {!--run 2x to parse the math plugin--}
}
    {exp:channel:entries
        channel="TWEET_CHANNEL"
        dynamic="no"
    } 
        {stash:entry_id}{entry_id}{/stash:entry_id}
        {stash:title}{title}{/stash:title}
        {!--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}
    {/exp:channel:entries}
{/exp:stash:set_list}

{!--output multi-channel list and tweet list--}
{exp:stash:get_list
    name="one" 
    prefix="st1"
}
    {!--output tweet on every third loop--}
    {if st1:count % 3 == 0}

        {exp:stash:get_list:nested
            name="two" 
            limit="1"
            match="#{st1:count}#" 
            against="two_count"
            prefix="st2"
        }
            {!--if no results, output main channel entry--}
            {if st2:no_results}
                <li>{st1:entry_id} : {st1:title}</li>
            {/if}
            {!--tweet--}
            <li>{st2:entry_id} : {st2:title}</li>
            {!--3rd main--}
            <li>{st1:entry_id} : {st1:title}</li>
        {/exp:stash:get_list:nested}

    {!--otherwise output main channel entry--}
    {if:else}
        <li>{st1:entry_id} : {st1:title}</li>
    {/if}
{/exp:stash:get_list}
5
  • Hello, thanks for your reply. See my comment on the previous answer. I think the same would apply here.
    – magicspon
    Commented Apr 2, 2015 at 10:10
  • You're right, so updated answer to output the third entry right after the tweet. Commented Apr 2, 2015 at 12:24
  • Yup... this does the job... I need to use pagination and output a form on the first page so I've had to adapt the code a little, but the core is there... I'll post it as an answer, just for shits and giggles!
    – magicspon
    Commented Apr 3, 2015 at 23:34
  • Any ideas how you would paginate these two lists.... I'm limiting the (E) to 5, and (T) 1.. Then using ajax to load in the next set of entries. Bugger is it's only paginating the (E) list... tricky!
    – magicspon
    Commented Apr 4, 2015 at 0:41
1

I would use conditionals and the modulus operator like this:

{exp:channel:entries channel="foo" limit=100"}

 {if count % 3 == 0}

    insert tweet here

 {if:else}

    insert entries here

 {/if}

{/exp:channel:entries}
3
  • Trouble is the Tweets are stored in another channel. Could use an embed to pull each in and if no results ignore and it continues on it's loop, but this will return duplicate tweets. Hence possibly the reference to stash. Also mentioned multiple channels for the main entries loop. Commented Mar 28, 2015 at 16:43
  • multiple channels use channel="foo|bar|etc". for the embed on tweets you could pass in an offset like this offset="({count} / 3) - 1". You'd probably need a math plugin though.
    – CreateSean
    Commented Mar 29, 2015 at 13:24
  • Hi, thanks for your reply. The problem with this approach is that this will result in the third entry (E) never appearing in the output.
    – magicspon
    Commented Apr 2, 2015 at 10:10

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.