• Resolved designforhumansstudio

    (@designforhumansstudio)


    Hi,
    First of all, I also find this Plugin great! I was looking for a solution for a publication list since quite a while and this plugin is exactly what I need.
    Unfortunately I am not able to create a nested loop, which goes through all publications and sorts them first under the headline of their publication_types and then following the publication_date. Here is my code:

    [loop type=publications orderby=publication_type]
    <h2 class=”publist”>[field publication_type]</h2>
    [the-loop publication_type=this orderby=field_num key=publication_date order=DESC]
    <p class=”publist”>[field image size=Medium size][field authors] ([field acf_date=publication_date date_format=”Y”]): [field title-link]. [field publisher].</p>
    [/the-loop]
    [/loop]

    The result is that the publications are shown three times and always under the publication_type of each publication. Only the sorting by date I could already sort out.

    I would be super thankful if you can give me a quick hint or a link to a documentation for nested loops.

    Best,

    Jens

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Ok, first of all this [loop type=...] [the-loop] is not a nested loop.

    a nested loop looks like this: [loop type=...] [-loop type=...]

    Try this:

    [loop type=publications orderby=publication_type]
    [pass field=publication_type]
    [-loop type=publications field=publication_type value='{FIELD}' oderby=... WHAT YOU LIKE]
    Your content here
    [/-loop]
    [/pass]
    [/loop]
    • This reply was modified 4 years, 1 month ago by polarracing.
    Thread Starter designforhumansstudio

    (@designforhumansstudio)

    Thanks a lot! This looks already much better:
    https://julianculp.academicwebs.com/publications/

    I now only need to solve the problem that the first loop goes through all publications and not only through the 2 different publication_type(s). How could I show each publication type only once?

    Here is my new shortcode:

    [loop type=publications orderby=publication_type]
    [pass field=publication_type]
    <h2 class=”publist”>[field publication_type]</h2>
    [-loop type=publications field=publication_type value='{FIELD}' orderby=field_num key=publication_date order=DESC]
    <p class=”publist”>[field image size=Medium size][field authors] ([field acf_date=publication_date date_format=”Y”]): [field title-link]. [field publisher].</p>
    [/-loop]
    [/pass]
    [/loop]

    Then you need to limit the pass to only one time.
    Try this:

    [loop type=publications orderby=publication_type]
    
    [pass field=publication_type]
    [if var=var not value={FIELD} and var_2=var]
    [-loop type=publications field=publication_type value='{FIELD}' oderby=... WHAT YOU LIKE]
    Your content here
    [/-loop]
    [/if]
    [/pass]
    [set var][field=publication_type][/set]
    [/loop]
    • This reply was modified 4 years, 1 month ago by polarracing.
    Thread Starter designforhumansstudio

    (@designforhumansstudio)

    Thank you so much! This last idea helped me to create the final shortcode:

    [set last][/set]
    [loop type=publications orderby=publication_type]
    [pass field=publication_type]
    [if var=last not value='{FIELD}’]
    <h2 class=”publist”>[field publication_type]</h2>
    [-loop type=publications field=publication_type value='{FIELD}’ orderby=field_num key=publication_date order=DESC]
    <p class=”publist”>[field image size=Medium size][field authors] ([field acf_date=publication_date date_format=”Y”]): [field title-link]. [field publisher].</p>
    [set last][field publication_type][/set]
    [/-loop]
    [/if]
    [/pass]
    [/loop]

    It works as it should. I am super happy about this solution!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Nested loops’ is closed to new replies.