Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-10-31 18:33:53

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,020
Website

[solved] Nth year counter from given start

In the old Parisian journals (newspapers) of the Belle Époque it was common to keep track of paper issues by using…

Nth année — No. N+1

The first part is counting the year from the first year the paper was published. A given issue would be 1er année in the first year, 2e année in the second, and similar thereon. (In English it would be 1st, 2nd, 3rd, 4th and then from thereon th…). For example, if a journal launched in 2016, it would now be 2e année — No. N+1

The second part would simply be a numeral of the issue for that year, recounting from ‘1’ when the new year turned.

I’m trying to figure out how to make an automatic counter that mimics that same idea, outputting the Arabic numeral (1, 2, 3, etc), based on a launch date of my definition. So for the first 12 months it outputs ‘1’, for the second 12 months it outputs ‘2’, and so on. I’m guessing it would involve the <txp:php> . . . </txp:php> tag, work with PHP date values, do some math, but that’s as far as this non-coder can surmise.

Any pointers?

For those wondering, the second part, the actual issue number, will not restart each year, but will actually be the ID for the latest article. Hopefully I’m not breaking any ancient librarian codes of conduct, or whatever. ;)


The text persuades, the *notes prove。

Offline

#2 2018-10-31 19:49:35

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: [solved] Nth year counter from given start

Depends on where you want it to appear. On an article list that’s not too hard, even “without” PHP, but for individual articles it’s a tough one. Unless

the second part, the actual issue number, will not restart each year, but will actually be the ID for the latest article.

Assuming that, you can get the first part (not on Windows) with

<txp:evaluate query='ceiling((<txp:posted format="%s" /> - your_start_timestamp) div 31557600)' />

where 31557600 = 365.25*24*60*60 is an approximate number of seconds in an average year. To get your_start_timestamp you can run (once)

<txp:php>
// Replace 2016-03-24 with your start date
echo strtotime('2016-03-24');
</txp:php>

and put the calculated value into <txp:evaluate />.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#3 2018-11-01 23:14:57

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: [solved] Nth year counter from given start

A more detailed tip is available now, in case somebody needs it.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#4 2018-11-02 09:24:28

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,911
Website

Re: [solved] Nth year counter from given start

That looks very interesting!!! At the moment I use the fha_time_diff plugin like <txp:fha_time_diff year="2004" month="11" day="18" /> which today returned 13 years, 11 months and 14 days. Is there a way to achieve that using the evaluate tag?


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#5 2018-11-02 18:21:16

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: [solved] Nth year counter from given start

colak wrote #314862:

Is there a way to achieve that using the evaluate tag?

Most probably yes, but it would be longer and slower than a dedicated plugin.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#6 2018-11-02 19:15:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 6,911
Website

Re: [solved] Nth year counter from given start

Got it! 👍


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github

Offline

#7 2018-11-03 09:35:36

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,020
Website

Re: [solved] Nth year counter from given start

etc wrote #314856:

A more detailed tip is available now, in case somebody needs it.

I haven’t had a chance to try anything yet, etc, but I will. Thanks so much for looking at this. I guess being it only needs to turn one day out of 365, automating it might be overkill. But then look at how much of the online world forgets to update their footer copyright years. ;)


The text persuades, the *notes prove。

Offline

#8 2018-11-03 11:02:15

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: [solved] Nth year counter from given start

colak wrote #314879:

Got it! 👍

For the record, year and month parts are easy:

<txp:evaluate query='floor((<txp:posted format="%Y%m%d" /> - 20120703) div 10000)' /> years
<txp:evaluate query='floor((<txp:posted format="%m%d" /> + 1200 - 0703) div 100) mod 12' /> months
since 2012-07-03.

The day part is tricky, since the number of days between two dates depends on month/year, e.g. 2 days between 2018-02-28 and 2018-03-02, but 5 days between 2018-03-28 and 2018-04-02.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#9 2018-11-05 13:06:53

Destry
Moderator
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,020
Website

Re: [solved] Nth year counter from given start

I’ve decided to use a custom field for the issue number (called ‘Issue’), instead of the latest article ID, because it provides more control and flexibility over the actual number I want. I can continue on this way, where each issue is a single article (tied to the latest article), because my posts will mostly be long-form and infrequent.

But then I started wondering, just for kicks, how I might tie multiple articles to a single issue. Being able to to this in a light-weight way without it getting to loopy or complex, would be an attractive function for anyone wanting to use Txp for managing a magazine. I know Stef set up something similar for us in TXP Mag, at least to achieve the same end goal (don’t remember how), but I’m guessing it could be refined at this point.

I’m not sure how to pull it off, but it seems the ‘straightforward’ way is to make a filter that worked in conjunction with the ‘Issue’ custom field; a snippet that recognized all articles in that field having the latest (largest) value.

For example, if the latest issue to be published will be ‘5’, and three draft articles are ready to go with 5 in the Issue field (to designate them to the fifth issue), how could that be targeted as an ‘latest issue’ filter (i.e. to output those three as a list)? You see what I mean? Sure, I can target the Issue field for a value of ‘5’, but it needs to be done automagically each time the value increases, without me having to manually fiddle in fields for more than just adding the latest issue numbers.

I’m guessing this is about doing some PHP math on the Issue field, or something, but… Just a guess.

N.B. I do not expect to have links to each back issue, as was provided in the TXP Mag. I’m only concerned with how the current issue appears for the cover’s sake. Past articles can be accessed individually via the ‘reading archives’. So it’s just the fancy boot out the door I’m concerned with. If anyone takes a screenshot of the homepage, it will show at any moment everything a person needs to know what the issue was at that time and what articles were in it. Likewise individual articles would/could have their respective Issue value tied to their publine, or whatever.

Bonus: How could you publish all three drafts in that issue at the same time (assuming you retain their latest draft dates at time of publish so there’s no conflicts)?


The text persuades, the *notes prove。

Offline

#10 2018-11-05 13:36:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: [solved] Nth year counter from given start

Destry wrote #314969:

[Issue numbers]

Yep, the mag was a hack job using a custom field for the issue as you propose here. The front page for an issues was a gbp_pl rule to translate /issue/N URLs into an article_custom search to grab the articles matching that issue CF.

How could you publish all three drafts in that issue at the same time.

Uhhh. Content->Articles. Checkboxes. Multi-edit->Change status to Live?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB