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.

Different headings if there are more related entries

February 02, 2011 5:50am

Subscribe [4]
  • #1 / Feb 02, 2011 5:50am

    kalkun

    4 posts

    Hello,

    trying to display different headings based on count for related items.

    Something like this:

    {reverse_related_entries channel="my_channel"}
        {if no_reverse_related_entries}{/if}
        {if "total_entries" >= "2"}
                 <h4>Heading2 for multiple items</h4>
    <p>        {if:else}<br />
            </p><h4>Heading1 for 1 item</h4><p>    <br />
            {/if}    <br />
    {/reverse_related_entries}

    Have tryed to put all af this into if-elseif-else statment.. The closest match gave me for Heading1 for 1 item, but two or more Heading2’s fof multiple items (because it loops 😊)..

    Any different ways to accomplish this?

  • #2 / Feb 02, 2011 4:28pm

    Sue Crocker

    26054 posts

    Hi, kalkun.

    Give {count} a try, and see if that works for you.

  • #3 / Feb 04, 2011 11:16am

    kalkun

    4 posts

    Tried count parameter as well.. same results

    {reverse_related_entries channel="my_channel"}
        {if no_reverse_related_entries}
        {if:elseif count >= 2}<h4>Heading2</h4>
    <p>    {if:else}</p><h4>Heading1</h4><p>{/if}<br />
    {/reverse_related_entries}

    It works as it should — if there is only one related entrie, then i get Heading1; and if there are more related entries then i get Heading1 for first and Heading2 for others.

    But is there a way to display only one Heading? limit=1 gives always Heading1..

  • #4 / Feb 05, 2011 3:23pm

    Greg Salt

    3988 posts

    Hi kalkun,

    Which version and build of EE are you using on this site?

    Cheers

    Greg

  • #5 / Feb 05, 2011 3:48pm

    kalkun

    4 posts

    Recent version — EE 2.1.3 build 20101220

  • #6 / Feb 07, 2011 2:47am

    John Henry Donovan

    12339 posts

    kalkun,

    Use your original method but change your syntax slightly

    {exp:channel:entries channel="my_channel" limit="1"}
    
    {reverse_related_entries status="open"}
    {if total_results == '1'}
    <h4>Heading1 for 1 item</h4>
    <p>{if:else}</p><h4>Heading2 for multiple items</h4>
    <p>{/if}</p>
    
    <p>{/reverse_related_entries}</p>
    
    <p><br />
    {/exp:channel:entries}

    Does that work for you?

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

ExpressionEngine News!

#eecms, #events, #releases