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.

Show random image

March 18, 2012 7:11pm

Subscribe [2]
  • #1 / Mar 18, 2012 7:11pm

    IJsbeer

    55 posts

    Hi all,

    I wonder if this is possible.
    I have a blog with >300 entries
    In many blogs there is a embedded video-link with it’s own custom_field (channel video by devdemon)
    But not all entries do have a video.

    I want to show at random 1 video in the sidebar of my blog, with a link to the entry.

    It’s normal behavior that the code I use will only show a video if the randomly chosen entry does have the custom_field video.
    What I’m looking for is the code that says:

    Choose at random an entry. If custom_field_video is not empty: show video.
    If else, go to next randomly chosen entry and check if cf_video is not empty. Repeat until the first entry with video is found. Show cf_video. Stop looking.

    This code will only show a video if I’m lucky…:-)

    {exp:channel:entries channel="blog" dynamic="off" orderby="random" limit="1"}
    {if cf_video}
            {video:embed_code}
    {/if}
    {/exp:channel:entries}

    May be there is some php-coding needed, but that’s not my core-business…

    Thanks in advance for thinking with me…

  • #2 / Mar 18, 2012 8:13pm

    the3mus1can

    426 posts

    Try something like this:

    {exp:channel:entries channel="blog" dynamic="off" orderby="random" search:cf_video="not IS_EMPTY" limit="1"}
    {if cf_video}
            {video:embed_code}
    {/if}
    {/exp:channel:entries}

     

  • #3 / Mar 19, 2012 5:58am

    IJsbeer

    55 posts

    Great! It’s magic when it works…:-) And it does… I like this one.

    Thanks!

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

ExpressionEngine News!

#eecms, #events, #releases