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.

Conditionals within an {exp:weblog:entries} tag

March 09, 2008 6:16am

Subscribe [4]
  • #1 / Mar 09, 2008 6:16am

    DanaK

    21 posts

    I do not think this is possible, but I figure I’ll post it to the boards see what comes up. I have a {exp:weblog:entries} tag that is grabbing information from two different weblogs, “Blog” and “Events.” I have a custom date field in “Events.” Is there a way to kinda combine the default entry_date of “Blog” and this custom_date of “Events” so that I can “orderby” the entry_date if it’s an entry from “Blog” and the custom_date if it’s an entry from “Events.”  So, conceptually (obviously, this code doesn’t work), something like:

    {exp:weblog:entries weblog="weblog1|weblog2"
    {if weblog=='weblog1'} orderby="date"
    {if:elseif weblog=='weblog2'} orderby="custom_date_field"{/if}}
    
    post content
    
    {/exp:weblog:entries}

    If not, it’s not a big deal. I guess I’m more curious for future reference.
    Thanks!
    ~dk

  • #2 / Mar 09, 2008 1:04pm

    Jared Farrish

    575 posts

    I’ve seen a couple of different ways to do this:

    {if weblog=='weblog1'}
    {assign_variable:orderby="date"}
    {if:elseif weblog=='weblog2'}
    {assign_variable:orderby="custom_date_field"}
    {/if}
    {exp:weblog:entries weblog="weblog1|weblog2" orderby="{orderby}"}
    
    post content
    
    {/exp:weblog:entries}

    Or…

    {if weblog=='weblog1'}
    {exp:weblog:entries weblog="weblog1" orderby="date"}
    
    post content
    
    {/exp:weblog:entries}
    
    {if weblog=='weblog2'}
    {exp:weblog:entries weblog="weblog2" orderby="custom_date_field"}
    
    post content
    
    {/exp:weblog:entries}
    {/if}

    In another thread, though, it was explained that you can’t do what you posted. It’s probably a good thing, too, since it makes the template code hard to read if you have that in there.

  • #3 / Apr 23, 2009 2:01pm

    grizzlies

    27 posts

    Am I correct in assuming you can’t use a pipe to separate weblogs within the conditional?

    Meaning this won’t work:

    {if weblog_id=="1|2|3"}

    Instead, you should use the OR operator:

    {if weblog_id=="2" OR weblog_id=="2" OR weblog_id=="3"}

    The former isn’t working for me, but the latter is. Is this right?

  • #4 / Apr 23, 2009 3:25pm

    Ingmar

    29245 posts

    Yes, that’s correct.

  • #5 / Apr 23, 2009 4:19pm

    grizzlies

    27 posts

    Thanks Ingmar.

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

ExpressionEngine News!

#eecms, #events, #releases