ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is it possible to store entry_id for use outside of loop?

October 26, 2011 11:57am

Subscribe [3]
  • #1 / Oct 26, 2011 11:57am

    SudlerLondon

    1 posts

    I would like to do this:

    Display a single random entry from a channel.

    Then display the remaining entries from the same channel, date ordered.

    So I need to filter out the first entry from the second list.

    NSM Transplant seems way over the top, I don’t think the Variables plugin can do this, I’m guessing I can’t assign the entry_id to a PHP varible?

  • #2 / Nov 07, 2011 12:08pm

    Noah Kuhn

    60 posts

    You could do this with an embed I think.

    Start with the main channel entries loop. Then within, pass the entry_id into an embed with a name of something like “exclude_this”

    {exp:channel:entries channel="YOUR_CHANNEL" orderby="random" limit="1"}
    {title}
    {whatever_else}
    
    {embed="includes/related_entries" exclude_this="{entry_id}"}
    {/exp:channel:entries}

    Then in the embed, just use the entry_id parameter with “not” to exclude the embedded entry_id ({embed:exclude_this}.

    {exp:channel:entries channel="YOUR_CHANNEL" entry_id="not {embed:exclude_this}" orderby="date" sort="desc"}
    {title}
    {whatever_else}
    {/exp:channel:entries}

    More information on embeds here

  • #3 / Nov 07, 2011 7:59pm

    John St-Amand

    865 posts

    Or you could use MX Jumper or Stash - both available from Devot-ee.com.  They enable you to declare a variable inside your entries loop for use outside the loop.  The variable can be anything you declare - url title, entry id, custom fields - anything.  They both work essentially the same way and are very effective for this purpose and provide performance benefits over multiple entries loops or embeds, since they don’t fire the template engine all over again.  Hope that helps you.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases