4

I need to output the most recent 3 entries from 4 different channels, followed by random entries from any of the four channels, but not including any of the most recent entries. Any idea how to accomplish this? I know how to display random entries, and I know how to display the 3 most recent entries of a channel, but not how to do the two things combined.

3 Answers 3

9

Pulling everyones answers together (including post from original StackExchange) and utilising Stash (https://github.com/croxton/Stash/tree/dev) as Jim suggested:

{exp:channel:entries channel="about" orderby="date" limit="3"}
   ..content..
   {exp:stash:set name="exclude" append="yes"}{entry_id}|{/exp:stash:set}
{/exp:channel:entries}

{exp:channel:entries channel="news" orderby="date" limit="3"}
   ..content..
   {exp:stash:set name="exclude" append="yes"}{entry_id}|{/exp:stash:set}
{/exp:channel:entries}

{exp:channel:entries channel="services" orderby="date" limit="3"}
   ..content..
   {exp:stash:set name="exclude" append="yes"}{entry_id}|{/exp:stash:set}
{/exp:channel:entries}

{exp:channel:entries channel="products" orderby="date" limit="3"}
   ..content..
   {exp:stash:set name="exclude" append="yes"}{entry_id}|{/exp:stash:set}
{/exp:channel:entries}

{embed="includes/random-entries" exclude="{exp:stash:get name="exclude"}"}

In a new template "random-entries", in an "includes": group...

 {exp:channel:entries channel="about|news|services|products" entry_id="not {embed:exclude}0" orderby="random" limit="10"}
    ..content..
 {/exp:channel:entries}
4
  • I think you can use another entries tag on the same template instead of an embed. That's where you might need to use stash's parse tag.
    – Jim Butts
    Nov 29, 2012 at 18:56
  • The problem is you won't be able to use a tag within another tags parameter: {exp:channel:entries channel="about|news|services|products" entry_id="not {exp:stash:get name="exclude"}0" orderby="random" limit="10"} won't be valid or parse correctly. Nov 30, 2012 at 10:04
  • It should work with parse="inward" (and possibly wrapping with Stash's parse tag, if needed). It might not be valid, but it would save an embed. Granted, it would only save one embed on one page in this situation.
    – Jim Butts
    Nov 30, 2012 at 14:42
  • Thanks - this is a great suggestion. I am actually using low variables (gotolow.com/addons/low-variables/docs) - so I was able to preparse the stash variable inside low variables like this: {exp:low_variables:single var='share_expanded_random' preparse:exclude='{exp:stash:get name="exclude"}'} and in the embed: entry_id="not {exclude}"
    – mheavers
    Dec 2, 2012 at 19:10
3

You might be able to do it using Stash.

You could try doing your first entries tag with the limit of 3 and order by date descending. In that loop, you could create a stash var of the piped result IDs, like "123|122|110".

You could then do a second entries tag and set the entry_id parameter to "not {exp:stash:your_var_name}" and filter by random. You may have to play around with {exp:stash:parse} for the second entries tag to get the parse order right.

0

I think you can probably do that with the offset parameter.

Your Answer

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

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