• Resolved s1s2

    (@s1s2)


    I’d like to automatically place events recorded in a special post-type on a timeline, ordering them from the oldest to the most recent.

    Given that the ACF Date Picker only goes back to 1927, at least over here, I created an ACF custom field called “acf_year” as a number type, and the following code:

    [loop type=timeline orderby=acf_year]
     <div class="milestone">
      <div class="milestone_title">[field title]</div>
      <div class="milestone_text">[field acf_milestone] <a href="[field acf_milestone_source]">[+]</a></div>
      </div>
      <div class="line"></div>
      <div class="milestone_year">[field acf_year]</div>
    [/loop]

    It works (mostly) fine. For some reason, a number like 811 is not placed before 1200, but from 1000 on, the events are ordered correctly.
    However, that’s not my main problem.

    My main problem is that certain dates are B.C. Can I use CCS to order from the oldest B.C. date to the most recent A.D. date?

    I thought about doing some operations with [CALC] but I cannot display a negative number in the timeline.

    Any idea would be greatly appreciated. Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • It works (mostly) fine. For some reason, a number like 811 is not placed before 1200, but from 1000 on, the events are ordered correctly.
    However, that’s not my main problem.

    You would have to enter 0811 to get that working properly.

    My main problem is that certain dates are B.C. Can I use CCS to order from the oldest B.C. date to the most recent A.D. date?

    How do you enter the B.C. dates?

    Thread Starter s1s2

    (@s1s2)

    Problem #1 (aka the number progression is not respected):

    I wouldn’t want the zero to appear in dates. I found a simpler solution with this syntax:

    [loop type=timeline field=acf_year orderby=field_num]

    Problem #2 (aka how to order BC > AD dates):

    At the moment, the best approach I found is to write BC dates as negative numbers, and have an additional ACF field where to specify BC or AD.
    For example: 2900 BC is inserted as -2900 and BC is specified.

    Then, I specified an IF condition that assigns a special CSS class to the ACF_year field:

    [if field=acf_yearnotation value="BC"]
         <div class="milestone_year bc">[field acf_year]</div>
    [/if]

    And finally, via CSS, I selected the minus sign at the beginning of the date and made it invisible by reducing its size to zero:

    .bc:first-letter {
    	font-size: 0;
    }

    Is it elegant? No.
    Do I have a better solution? Also, no.

    • This reply was modified 3 years, 10 months ago by s1s2.

    But if you have another field telling you if B.C. or A.D. why you need negative values.

    Just use acf_yearnotation & acf_year for filtering the loop. if you are looping AD use sort order ASC or DESC for acf_yearnotation to get right order.

    your case is similar to one of my client’s project where he wanted to sort orderby a field but display a different data in frontend. what I did to resolve it was to add an additional custom field just to display it for each entry. let’s call the field ‘displayname’.

    try:

    [loop type=timeline field=acf_year orderby=field_num]
         <div class="milestone_year bc">[field displayname]</div>
    [/loop]
    Thread Starter s1s2

    (@s1s2)

    I misread the documentation and assumed that ASC/DESC was only considering the post date (which is irrelevant in my case):

    order - ASC (ascending/alphabetical) or DESC (default: descending/from most recent date)

    Instead, it works perfectly, as @polarracing has suggested. Thank you!

    In the end, the code is as follows:

    [loop type=timeline field=acf_yearnotation value="BC" orderby=field_num key=acf_year order=DESC]
      <div class="milestone">
       <div class="milestone_title">[field title]</div>
       <div class="milestone_text">[field acf_milestone] <a href="[field acf_milestone_source]">[+]</a></div>
      </div>
      <div class="line"></div>
      <div class="milestone_year">[field acf_year] [field acf_yearnotation]</div>
     [/loop]
     
     [loop type=timeline field=acf_yearnotation value="AD" orderby=field_num key=acf_year order=ASC]
       <div class="milestone">
       <div class="milestone_title">[field title]</div>
       <div class="milestone_text">[field acf_milestone] <a href="[field acf_milestone_source]">[+]</a></div>
      </div>
      <div class="line"></div>
      <div class="milestone_year">[field acf_year] [field acf_yearnotation]</div>
     [/loop]
    • This reply was modified 3 years, 10 months ago by s1s2.

    One way this could be resolved, is with a new feature. In addition to orderby=field_num, it would be useful to have orderby=field_date, where the field contents is treated as a date.

    I have a field containing an event date, e.g. 1 Oct, and I can format it as a date using [format date=”…”]. I just can’t order it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Ordering posts by historical dates (B.C. and A.D.)’ is closed to new replies.