1

I'm trying to load a random channel entry on page landing, while excluding that entry from the navigation to view more in the sidebar.... Here's what i want to do, but I'm not sure how to make this work...

{exp:channel:entries
  channel="success_story"
  dynamic="no"
  orderby="random"
  limit="1"
}
{content}
{/exp:channel:entries}

<ul>
{exp:channel:entries
  channel="success_story"
  entry_id="not (entry_id from above)"
}
<li>{title}</li>
{/exp:channel:entries}
</ul>
2

You can do this using an embed.

{exp:channel:entries
  channel="success_story"
  orderby="random"
  dynamic="no"
  limit="1"
}
{content}
{embed="group/embed" eid="{entry_id}"}
{/exp:channel:entries}


<!-- Then create the group/embed template (call it whatever you want) and put this -->
<ul>
{exp:channel:entries
  channel="success_story"
  entry_id="not {embed:eid}"
  orderby="random"
}
<li>{title}</li>
{/exp:channel:entries}
</ul>

You could use Stash too, but maybe for another day. :)

1
  • simple and worked perfectly!
    – brunam
    May 28 '13 at 14:57
1

Here's a Stash way:

Stash the channel entries. The order doesn't matter.

{exp:stash:set_list name="entries" parse_tags="yes"}
  {exp:channel:entries channel="success_story"}
    {stash:id}{entry_id}{/stash:id}
    {stash:title}{title}{/stash:title}
    {stash:content}{content}{/stash:content}
  {/exp:channel:entries}
{/exp:stash:set_list}

Output one entry randomly and stash the ID.
Use parse_tags="yes" to be able to nest an {exp:stash:set}.

{exp:stash:get_list 
  name="entries"
  orderby="random"
  limit="1"
  parse_tags="yes"
}
  {content}
  {exp:stash:set name="random_entry_id"}{id}{/exp:stash:set}
{/exp:stash:get_list}

Output everything except the random entry.
You can control the order here using the orderby param.

<ul>
{exp:stash:get_list
  name="entries"
  orderby="date"
  match="#^(?!{exp:stash:random_entry_id}$).*$#"
  against="id"
  parse="inward"
}
  <li>{title}</li>
{/exp:stash:get_list}
</ul>

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.