Support » Plugin: Custom Content Shortcode » Loop passing the year

  • [pass list=1~5] lets me create a loop that generates the range 1..5.

    I’d like to be able to generate a range based on the year, eg.
    [pass list=2015~2018]
    where 2018 is the current year.

    Is it possible to ascertain and use the “current year” in either [pass] or [loop] or [for], and output:

    • 2015
    • 2016
    • 2017
    • 2018
    • This topic was modified 5 years, 5 months ago by iantresman.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter iantresman

    (@iantresman)

    This gets me the year, but I don’t know how to use it in a loop. Here is what I tried:

    [set year][today format=Y][/set]
    The current year is: [get year]
    List of years:
    [pass item=2016-{year}]
    <li>{item}</li>
    [/pass]

    and this:

    [set year][today format=Y][/set]
    The current year is: [get year]
    List of years:
    [pass now=date format=Y}]
    [-pass year=2016~{now}]
    <li>{year}</li>
    [/-pass]
    [/pass]

    I’m hoping to see:
    The current year is: 2018

    • 2016
    • 2017
    • 2018
    • This reply was modified 5 years, 5 months ago by iantresman.
    • This reply was modified 5 years, 5 months ago by iantresman.

    Hi,

    Why do you need the current year? If you need it for a loop to match with the year of publish, you can pass more years in the future. If there is no match with a year, nothing will display for that year.

    [pass list=2016~2022]
    [loop type=post year={ITEM}]
    
    [if first]
    <h3><span id="{ITEM}">{ITEM}</span></h3>
    [/if]
    <a href="[field url]">
    [field image size=medium]
    </a>
    
    [/loop]
    [/pass]

    Peter

    Thread Starter iantresman

    (@iantresman)

    That’s what I like, a different approach. Thank you!

    Thread Starter iantresman

    (@iantresman)

    …but out of interest, is there a way to get the current year into a pass/loop?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Loop passing the year’ is closed to new replies.