Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

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

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
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. ;)

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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 />.

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

Re: [solved] Nth year counter from given start

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

Offline

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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.

Offline

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

Re: [solved] Nth year counter from given start

Got it! ?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

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

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
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. ;)

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

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.

Offline

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

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
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)?

Offline

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

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,498
Website GitHub

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.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#11 2018-11-05 14:17:38

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [solved] Nth year counter from given start

Bloke wrote #314971:

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.

That seems pretty straighforward, assuming that plugin is still usable. I’ll check.

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

Haha… I live too long in my little nematode routines of simplicity and dankness.

Offline

#12 2018-11-05 14:25:36

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [solved] Nth year counter from given start

Better still, having a look in in TXP, my old friend. (Wow, running 4.7.1) Grabbed gpb_perm_links from plugin composer and will see how templates are set up.

Offline

#13 2018-11-06 09:17:09

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [solved] Nth year counter from given start

Destry wrote #314976:

Better still, having a look in TXP, my old friend. (Wow, running 4.7.1) Grabbed gpb_perm_links from plugin composer and will see how templates are set up.

Well… spent some time poking around in my old friend. Heh.

Having some trouble if anyone can help me out. It could be a stone that kills three birds:

  1. Making some headway to putting TXP right (baby steps)
  2. Clearing up variable docs for people like me who need it.
  3. Getting the ‘Issue’ functionality working in my own project.

Here’s what I notice in TXP Mag admin-side, and perhaps a good place to start:

  • Content > Macros panel. There’s a macro, in_issue, that’s apparently involved with Issues functionality somehow, but macros seem to be broken in TXP. If you go to the panel and select the macro for edit mode to see what it looks like, nothing happens. And there’s some progress bar turning perpetually.
  • Admin > Permanent Links. There’s an error thrown on the panel. And if you try to open or edit any of the three created link patterns — two of which are seemingly relevant to Issues handling — you see the same thing in each case, only two fields filled: name of link and section it applies to. Beats me how the patterns are created.
  • Presentation > Forms. All of the form type widgets are expanded and can not be closed, whether individually or all at once using the ‘Collapse all’ link. While the forms themselves seem to be usable/editable, the expanded lists make it hard to navigate and work with them.

Btw, both plugin panels have complex forms that are just a mess. I hope plugin authors make better efforts going forward to usabilitize their UIs. Seriously, that should be a release requirement. And so should proper plugin documentation!

Overall, I think these are barriers to some degree of me being able to look at and map how the Issues functionality works in TXP Mag, which I can’t figure out yet. The variables, as mentioned, are another problem for me too.

For example, in the ‘section’ form, page_issue, it contains these seemingly relevant variables — issue, issue_month, and issue_year:

<txp:variable name="issue" /> <span class="emdash"><txp:variable name="issue_month" /> <txp:variable name="issue_year" /></span>

And in the ‘article’ form, articles_on_front_page, it also contains contains the issue variable, and another for feat_title:

<div id="toc">
<h2>In this issue</h2>
<txp:smd_featured label='issue_<txp:variable name="issue" />' wraptag="dl">
<txp:variable name="feat_title"><txp:smd_featured_info item="title" /></txp:variable>
<dt><txp:permlink><txp:if_variable name="feat_title" value=""><txp:title /><txp:else /><txp:variable name="feat_title" /></txp:if_variable></txp:permlink></dt>
<dd><txp:smd_featured_info item="description" /></dd>
</txp:smd_featured>
</div>

But where are these variables defined? And how does one know (concerning my repo issue question for docs)? I can’t try to mimic the logic in my project until I understand how it’s supposed to layer together in the mag. I’m having trouble mapping and unpacking it. The macro and PL problems mentioned above might be a factor there too. I don’t know.

Can anyone toss me a bone? I don’t want to have to look at Stef alone, but he’s got the history here with me. Would etc be interested in a mag account? It is a Txp site. ;)

After getting these immediate issues ironed-out, the next thing I’d want to do is modernize the tag architecture in the mag, and drop any unnecessary plugins. Right now the mag seems to have a lot of detritus festered about the panels and markup. Hard to tell what you’re supposed to be looking at. I think the number of forms could/should be consolidated too, and renamed to a more intuitive scheme. I might be guilty there back in the day, but, you know, improve as you go.

Offline

#14 2018-11-06 09:31:51

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

Re: [solved] Nth year counter from given start

Destry wrote #315004:

Would etc be interested in a mag account? It is a Txp site. ;)

Just don’t let me write anything but code :-)

Offline

#15 2018-11-06 09:41:20

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [solved] Nth year counter from given start

etc wrote #315005:

Just don’t let me write anything but code :-)

Just don’t let me write anything but text!

We might have a partnership.

I’ll let Stef set you up. He probably knows what email to use.

Offline

Board footer

Powered by FluxBB