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.

Nesting lists using reverse related entries

April 02, 2009 1:18pm

Subscribe [3]
  • #1 / Apr 02, 2009 1:18pm

    adamwiggall

    178 posts

    All,

    This code is doing nearly all that I need it to.

    {reverse_related_entries status="open"}
                            
       {if count == 1} {!-- This ensures a heading and ul are opened once only --}
           <h5>Showtimes</h5>
    <p>       <ol id="showtimes"><br />
        {/if}<br />
                            <br />
             {if '{entry_date format="%U"}' >= '{current_time format="%U"}'} {!-- This gets future entries only --}<br />
                <li>{date_heading display="daily"}{entry_date format="%l, %m-%j"}{/date_heading}</li><br />
                <li>{entry_date format="%g:%i"}</li><br />
              {/if}<br />
                                                    <br />
         {if count == total_results} {!-- This closes the ul when all entries are displayed --}<br />
             </ol><br />
         {/if}<br />
                            <br />
    {/reverse_related_entries}

    It outputs a list of movie showtimes like so

    Showtimes

    <ol id="showtimes">

    <li>Thursday, 04-2</li>
    <li>4:30</li>
    <li></li>
    <li>7:00</li>
    <li></li>
    <li>9:30</li>
    <li>Friday, 04-3</li>
    <li>7:00</li>
    <li>4:30</li>
    <li></li>
    <li>7:00</li>
    <li></li>
    <li>9:00</li>
    </ol>

    I need it to nest a ol within each li (date_heading) like so,

    Showtimes

    <ol id="showtimes">

    <li>Thursday, 04-2
    <ul>
    <li>4:30</li>
    <li>7:00</li>
    <li>9:30</li>
    </ul>
    </li>

    <li>Friday, 04-3
    <ul>
    <li>7:00</li>
    <li>4:30</li>
    <li>7:00</li>
    <li>9:00</li>
    </ul>
    </li>

    </ol>

    Does anyone know how this could be achieved?

    Thanks in advance,

    Adam

  • #2 / Apr 02, 2009 6:35pm

    Dan Lovejoy

    115 posts

    Do you have PHP enabled for this template already? (input or output?)

  • #3 / Apr 02, 2009 6:40pm

    jpaylor

    84 posts

    Hey Adam,

    You’re almost there and should be able to achieve this with a little tweaking,

    I’ve noticed some list items in your example output are empty on the date_heading tag, which is correct because it’s still within the same day on that particular loop, so you should be able to use this to your advantage seing as you only want to open a new nested list every time there is a new day…

    Replace:

    <li>{date_heading display="daily"}{entry_date format="%l, %m-%j"}{/date_heading}</li>

    With the following:

    {date_heading display="daily"}{if count > 1}</ul></li>{/if}<li>{entry_date format="%l, %m-%j"}<ul>{/date_heading}

    The above code should output the day on a daily basis, and open a new list after it which the list items in the code below that would then be put into. The code also closes the previous list, and you will want to add the same to the {if count == total_results} section to make sure everything is closed in the end, as follows:

    {if count == total_results} {!-- This closes the ul when all entries are displayed --}
             </ul></li></ol>
         {/if}

    Hopefully this should work, but it’s difficult to get my head around it without a working copy to test with in front of me!

  • #4 / Apr 02, 2009 6:53pm

    Dan Lovejoy

    115 posts

    Ahh- I thought {count} was not available in reverse_related_entries, but it appears that it is:

    http://expressionengine.com/docs/modules/weblog/reverse_related_entries.html (See comments)

  • #5 / Apr 03, 2009 2:16pm

    adamwiggall

    178 posts

    JonnyUK,

    Tried that but didn’t quite get the right result.

    Showtimes

    <ol id="showtimes">
    </ul></li><li>Friday, 04-3<ul>
    <li>7:00</li>
    </ul></li><li>Thursday, 04-9<ul>
    <li>4:30</li>
    <li>7:00</li>
    <li>9:00</li>
    </ul></li></ol>

    It’s not far out, just that first </ul> and </li> is killing it.

    I appreciate the help, do you have any further thoughts?

    Adam

  • #6 / Apr 03, 2009 2:23pm

    adamwiggall

    178 posts

    JonnyUK,

    Cancel that I have it.

    Changed the first conditional to

    
    {date_heading display="daily"}{if count > 2}</ul></li>{/if}<li>{entry_date format="%l, %m-%j"}<ul>{/date_heading}
    
    

    Working like a charm.

    Thanks a lot!

    Thanks Dan too!

  • #7 / Apr 05, 2009 8:32am

    jpaylor

    84 posts

    Hi Adam,

    haha, did suspect it may not have been exactly right, glad you’ve sorted it though!

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

ExpressionEngine News!

#eecms, #events, #releases