Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2018-11-06 17:18:35

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

Re: [solved] Nth year counter from given start

I think I’ve found the source of the Rhine. A form called head_context in the mag:

<txp:hide>
==========
Lists of sections that:
* have article content in them (in the order they should appear in lists)
* are aggregates (list-of-other-sections/categories)
* have advertising content (first empty item indicates front page)
==========
</txp:hide>
<txp:variable name="column_sections">from-the-editor, community-spotlight, site-watch, extensionalism, independents-frontline, hope-for-the-future, meaningful-labour</txp:variable>
<txp:variable name="aggregate_sections">columns, exhibit, issues, topics</txp:variable>
<txp:variable name="ad_sections">, advertise, columns, issues, topics, exhibit, <txp:variable name="column_sections" /></txp:variable>
<txp:php>
// query_columns is used in the "in_issue" macro
//TODO: incorporate this into issue_info() too?
global $variable;
$variable['query_columns'] = "'". join("','", do_list($variable['column_sections'])) . "'";
</txp:php>

<txp:hide>
==========
Can use these to test if value="1" in templates
==========
</txp:hide>
<txp:variable name="is_column"><txp:if_section name='<txp:variable name="column_sections" />'>1<txp:else />0</txp:if_section></txp:variable>
<txp:variable name="is_aggregate"><txp:if_section name='<txp:variable name="aggregate_sections" />'>1<txp:else />0</txp:if_section></txp:variable>
<txp:variable name="is_landing"><txp:if_individual_article>0<txp:else />1</txp:if_individual_article></txp:variable>
<txp:variable name="has_ads"><txp:if_section name='<txp:variable name="ad_sections" />'><txp:if_status status="404"><txp:if_section name="">0<txp:else />1</txp:if_section><txp:else />1</txp:if_status><txp:else />0</txp:if_section></txp:variable>
<txp:variable name="has_feed"><txp:php>global $pretext; echo safe_field('in_rss', 'txp_section', "name='".doSlash($pretext['s'])."'");</txp:php></txp:variable>

<txp:hide>
==========
Determine the Mag Issue context. It's either:
a) From the URL (/issues/N that has passed the gbp_permanent_link CF check)
b) From the current individual article's "Issue" custom field
c) From the Issue CF of the most recent past live article in the mag content
==========
</txp:hide>

<txp:variable name="issue" value="0" />
<txp:php>
function issue_info($iss = '0') {
   global $variable, $pretext;
   static $issue_row;
   static $issue_stamp;
   if (!isset($issue_row) && !$issue_row) {
      $iss_clause = ($iss != '0' && is_numeric($iss)) ? " AND custom_1='".doSlash($iss)."'" : '';
      $post_clause = (isset($pretext['month']) && $pretext['month']) ? " AND Posted LIKE '".doSlash($pretext['month'])."%'" : ' AND Posted < NOW()';
      $issue_row = safe_row('MAX(custom_1) AS custom_1, MAX(Posted) AS Posted', 'textpattern', "Section IN (" . join(',', quote_list(do_list($variable['column_sections']))) . ")" . $post_clause . " AND Status='4'" . $iss_clause);
      $issue_stamp = strtotime($issue_row['Posted']);
   }
   return array($issue_row, $issue_stamp);
}
</txp:php>

<txp:if_status status="200">
  <txp:if_section name="issues">
    <txp:php>
      global $variable, $pretext;
      $date = array(); // Holds the ?month URL param portions
      $uri = serverSet('REQUEST_URI');
      $qs = serverSet('QUERY_STRING');
      $qs = ($qs) ? '?'.$qs : '';
      $uri = str_replace($qs, '', $uri);
      $uri = do_list($uri, '/');
      $pos = array_search('issues', $uri) + 1;
      if (isset($uri[$pos])) {
         if (is_numeric($uri[$pos])) {
            $uri[$pos] = (int) $uri[$pos];
            // Anything above 2001 is assumed to be a year. Limits the mag to 2001 issues!
            if ($uri[$pos] < 2002) {
               $variable['issue'] = $uri[$pos];
            } else {
               // Year
               $date[] = $uri[$pos];
               $pos++;
               if (isset($uri[$pos]) && is_numeric($uri[$pos])) {
                  // Month
                  $date[] = str_pad( (int) $uri[$pos], 2, '0', STR_PAD_LEFT);
                  $pos++;
                  if (isset($uri[$pos]) && is_numeric($uri[$pos])) {
                     // Day
                     $date[] = str_pad( (int) $uri[$pos], 2, '0', STR_PAD_LEFT);
                  }
               }
               // Fake Txp's month filter
               $pretext['month'] = join('-', $date);
            }
         }
      } else {
         $variable['issue'] = 0;
      }
      $variable['is_issue_landing'] = ($variable['issue']) ? '1' : '';
    </txp:php>
  <txp:else />
    <txp:if_individual_article>
      <txp:if_custom_field name="issue">
        <txp:variable name="issue"><txp:custom_field name="issue" /></txp:variable>
      </txp:if_custom_field>
    </txp:if_individual_article>
  </txp:if_section>
</txp:if_status>

<txp:hide>
==========
No issue found: get latest Issue CF from latest article
==========
</txp:hide>

<txp:if_variable name="issue" value="0">
  <txp:php>
    global $variable;
    list($issue_row, $issue_stamp) = issue_info();
    $variable['issue'] = $issue_row['custom_1'];
  </txp:php>
</txp:if_variable>

<txp:hide>
==========
Create the Month/Year of Issue
==========
</txp:hide>
<txp:php>
  global $variable;
  list($issue_row, $issue_stamp) = issue_info($variable['issue']); // In case it's not been set up already
  $when = ($issue_stamp) ? $issue_stamp : time();
  $variable['issue_month'] = date('M', $when);
  $variable['issue_year'] = date('Y', $when);
</txp:php>

The php is beyond me, but I’m guessing by looks of keywords, this is where the magic happens for filling things like: <txp:variable name="issue" />, etc.

So my question at this point is just this: If I’m not trying to mimic the past issues links just yet… If all I want right now is the ability to create the mag’s home page list of article in the current issue… What pieces of the puzzle do I need to replicate that in my own project?

I think that would be a good start, combined with the bit from etc at head of this thread for the year count.

Offline

#26 2018-11-06 17:47:55

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

Re: [solved] Nth year counter from given start

A little more clarity on what I’m doing at my end, compared with the Mag.

Columns

I did not originally set out to use columns like the Mag does, but I have sections that could be used that way, and the more I look at it, the more I’m growing on the idea. I like how the columns are explained on a sticky list like that. I could set that up easy enough. My only hesitation is I didn’t want to use .../section/title URLs, I wanted just .../title URLs for simplicity because the site is already sitting at a subdomain. I’ll have to think about that.

Issues

As mentioned, I did not intend to keep historical links for past issues. I was only concerned about having a list of articles for the current issue on the home page, and then letting the archive work by itself for accessing individual articles. Especially as there will not be high turnover at my site, and perhaps not many issues with more than one article. :)

But, again, I’m liking the convenience that these past issue lists provide. So, that’s a possible phase 2 at this point.

Homepage

So if I really keep it simple, as originally intended. I only need three things to happen, all on the homepage:

  1. The 1st Year — No. n parts in the left side of banner.
  2. The Issue date (ideally DD Month YYY) in the right side of banner.
  3. The current issue list of articles at top of the homepage main area.

The first I should be able to setup using etc’s, script for the birthdate and then using <txp:variable name="issue" /> for the issue number.

The second should be similar, I think, using: <txp:variable name="issue_month" /> and <txp:variable name="issue_year" />. I’m not sure about the day part though. The mag doesn’t have that.

The third part I should also be able to setup using the mag’s forms.

I just need some help knowing which parts of the head_context form to pick out to make it all run.

Offline

#27 2018-11-07 09:31:36

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

Re: [solved] Nth year counter from given start

I’ve decided to keep my site as dead simple as possible. It has some notions of being published in ‘issues’, but it’s not a full-fledged magazine like TXP so there’s no need for back issue links and back-issue archives and all that.

An update on my objectives…

As mentioned before, I use a simple sub.domain.tld/title URL pattern. That’s enough to make every link unique and that’s all I want. I’m not trying to reflect a pseudo site structure in my URLs. Homie don’t care anymore.

While I have a number of sections that will never be visible as such to visitors (I simply use them to make convenient article lists by section name type), there are two main views to my site: homepage and ‘stories’ (what I call full articles). Each has its own masthead and main content, quite different in both cases.

The homepage is essentially being modeled like an old Parisian journal. The masthead provides all the journal’s typical details:

  • Name of rag
  • Editor (moi)
  • Year since founded (thank you, etc.)
  • Issue number
  • Date of issue
  • (other static details)

The homepage essentially serves as the site archive too. Think of it as the journal’s index for all published articles to date, organized in broad section/type lists. The main content area is composed of two regions in this order:

  • Current Issue (highlight list of articles in latest issue, probably never more than two titles, generally only one)
  • Archive (not called that, but what it is, an archive of all published articles)

The items in bold in the above two lists are the parts that concern my interests/needs in this thread for handling ‘issue’ stuff.

The ‘year since’ and ‘issue number’ are handled with this, easy-peasy:

<p class="issue"><txp:evaluate query='ceiling((<txp:posted format="%Y%m%d" /> - 20171223) div 10000)' /><sup>st</sup> Year — &#8470; <txp:custom_field name="issue" /></p>

The issue number simply pulls from the latest article’s CF issue value, which will always be the current issue number, right? Right.

The ‘issue date’ is also handled easily, using the latest article’s post date:

<p class="date"><txp:posted /></p>

Since any articles in a given issue will have the same DD/Month/YYYY time (different only by the seconds), this works nicely for my needs.

It works because I’m not keeping track of back-issues and back-issue links. Once the homepage reflects a new issue (by posting one or two new articles in a new date with new issue number) the old issue information is no longer relevant or needed. Poof! What I will do though, is take a screen grab of each new homepage issue, and that will be a personal record of them. I’m not even sure I care about it. I guess it’s the equivalent of a Wayback Machine capture (though I’m not allowing the site in the Wayback; will be requesting they do not archive it, in fact).

If there could be a plugin that does the screenshots automagically when a new article series with higher issue number is published, and saves the grabs to the Files panel too, that would be cool, I guess. But I can do it manually.

So the only thing I need to figure out now to be handled dynamically, is the ‘current issue’ list. It would be intelligent enough to know what articles are in the latest issue and output there titles only (no descriptions). That’s it. But I can’t figure that out from the mag, which is overkill code in this case and too damn complicated for me to figure out. I’ve tried pulling variables and php code out of what seems the relevant places, but nothing works. I get no results, no output.

I think it would be a lot easier to just create what I need for my situation from scratch. But I’m pretty sure this require some modicum of the mag’s PHP wizardry. I just don’t know how to do it. Can anyone help me with this ‘current list’ part? If I get that done. This thread is done too. ;)

Stories

Just to give you the other side of the token…

The masthead here loses all the publishing details except for rag name (logo) and acquires a stories-oriented navigation bar (previous, next, latest, all…). Because most of my articles are quite long, the stories nav bar is repeated just above the footer too. Finish reading a story, jump to the next one. ;)

The main content area is the big enchilada you expect (hed, dek, byline, word count, excerpt, body, endnotes, whatever)

There are no other views in this site, just homepage and stories. All auxiliary things like Contact, Policies, etc which are linked in the footer will go to wion.com (the origin domain), where my work presence will be set up and available at the same time. A double site launch!

Whether that kind of hierarchical data management structure across domain levels is practical, I’m not sure yet, but I like it from the ‘authority’ standpoint, which might serve better in professional situations. It will probably make more sense when can actually experience it. ;)

Offline

#28 2018-11-07 11:54:47

etc
Developer
Registered: 2010-11-11
Posts: 4,550
Website GitHub

Re: [solved] Nth year counter from given start

Destry wrote #315035:

Can anyone help me with this ‘current list’ part?

You can calculate the “shift” years number and store it in a variable:

<txp:variable name="shift" escape="integer">
<txp:php>echo floor((strftime("%Y%m%d") - 20171223)/10000);</txp:php>
</txp:variable>

Then plug it into <txp:article_custom />:

<txp:article_custom time='2017-12-23 +<txp:variable name="shift" />years' />

Offline

#29 2018-11-07 13:26:43

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

Re: [solved] Nth year counter from given start

etc wrote #315036:

You can calculate the “shift” years

Thanks for looking at this, etc. If I understand, your variable is assuming a given issue is a 12 months interval of time?

Unfortunately, the periodicity is irregular. Stories are published when they are ready. That may be 3 months, or it may be 3 years. Sometimes I might decide to publish multiple stories which would influence the time before an new issue was ready as well.

This is what Bloke has under the ‘current issue list’ on the TXP Mag home page:

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

I installed the plugin and tried to mimic it all, but I’m not having luck. There’s more to the obvious eye going on there somewhere, but heck if I can figure it. Sorry.

Offline

#30 2018-11-07 13:33:53

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

Re: [solved] Nth year counter from given start

Just for the record, here’s what I have so far.

Two articles, both published 29 December 2017 (different only by hours/minutes/seconds). Both having CF issue value 1. So I would expect these two articles to appear in the current issue list at this point.

In homepage for the “current issue” list:1

<txp:hide>==========================================================================================
Variable to calculate the “shift” time (years) between issue numbers.
Then called in homepage for current issue articles.
==========================================================================================</txp:hide>
<txp:variable name="shift" escape="integer">
<txp:php>echo floor((strftime("%Y%m%d") - 20171223)/10000);</txp:php>
</txp:variable>

<txp:article_custom time='2017-12-23 +<txp:variable name="shift" />years' form="current_issue_list" />

And in the current_issue_list form:

<dl class="current">
  <dt><a href="<txp:permlink />"><txp:title /></a></dt>
  <dd><txp:custom_field name="deck" /></dd>
</dl>

I get one article, but not two.

————————————

1. Btw, when I put this variable in my dedicated variables form that outputs at the very top of the DOM (before the html tag) it doesn’t work. But if I put the variable just before where I call it. It works. Why the difference?

Last edited by Destry (2018-11-07 13:38:52)

Offline

#31 2018-11-07 14:15:43

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,191
Website

Re: [solved] Nth year counter from given start

I admit to having got a bit lost here, but it sounds ever more intriguing the more you write. And you know I think what you have to say is interesting, so it seems a pity (to me at least) that you will eradicate past issues but I also understand your thinking…*

That said … could you not do that all a bit more simply and:

  • Use a custom field called issue to hold the issue number of the respective article. You haven’t got a ton of articles so it’s not a great effort that you have to manually set that.
  • Use a combination of sort="issue desc" and if_different to skip all later articles with a different issue number. If it doesn’t work with if_different, you should be able to set a variable with the first issue number it outputs and then use smd_if to prevent other articles from showing. There’s probably a way to do that with txp:evaluate too. Maybe Oleg will post a cleverer alternative ;-)
  • Don’t bother with the screen grab as your text is still in Textpattern, so not lost to you, just no longer publicly accessible. A PDF or epub format might be better than a screen grab as you can easily extract the text from it if you should ever need it again.

That should allow you to switch over issues as soon as you post an article with a new issue number and have as many articles as you want in that issue (if you need more than 10, you’ll need to set limit="max-number-of-articles-per-issue").

*By way of example, I had to look quite hard to find your two past articles on textpattern building blocks and semantics


TXP Builders – finely-crafted code, design and txp

Offline

#32 2018-11-07 14:20:26

etc
Developer
Registered: 2010-11-11
Posts: 4,550
Website GitHub

Re: [solved] Nth year counter from given start

Ok, I think I have misunderstood the “issue” meaning, sorry. If I get it right now, you can try

<!-- get the latest issue -->
<!-- add sort="issue DESC" to article_custom if "latest" means "issue number", not "date" -->
<txp:variable name="latest" escape="trim">
<txp:article_custom limit="1">
<txp:custom_field name="issue" />
</txp:article_custom>
</txp:variable>

<!-- retrieve the latest articles -->
<txp:article_custom issue='<txp:variable name="latest" />' form="current_issue_list" />
Destry wrote #315038:

I get one article, but not two.

Btw, when I put this variable in my dedicated variables form that outputs at the very top of the DOM (before the html tag) it doesn’t work. But if I put the variable just before where I call it. It works. Why the difference?

Anomalies they are, something is messed up.

Offline

#33 2018-11-07 14:23:36

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

Re: [solved] Nth year counter from given start

I just looked around for a publishing system specifically for editorial publishing (versus general website design/dev) and there is practically nothing. In fact the only thing I can find is mention of systems that media publishers created, and they are not sharing, except among themselves in some cases. Boo!

I know Bloke did no small amount of magic just to get TXP Mag operating more like a real magazing, at least on the organizational side. There is still a lot that could be done on the actual editorial/component side. And even now, just trying to figure out how to create an “issue list”. It’s not straightforward (for me).

I know, coming from the CSF work and folks for several years, that there is a lot of interest in creating real editorial workflows, and setting up magazine-like sites, even for companies/orgs that are not publishers. But most have to hack some makeshift solution together, often using WordPress, the do-it-all go to if you throw enough plugins at it.

It’s neither here nor there, but I think if I was building a CMS today, it would be specifically for editorial publishing and workflow, not website design in general (a saturated market anyway). The design seems like a layer that you can do regardless. But a system designed around editorial workflow… I would love to see and touch one of those just to know what’s going on there.

Back to your regular bat channel.

Offline

#34 2018-11-07 14:31:45

etc
Developer
Registered: 2010-11-11
Posts: 4,550
Website GitHub

Re: [solved] Nth year counter from given start

Or, if I have misunderstood the “issue” meaning again, and you have no issue custom field

<!-- get the latest issue date -->
<txp:variable name="latest" escape="trim">
<txp:article_custom limit="1">
<txp:posted format="%Y-%m-%d" />
</txp:article_custom>
</txp:variable>

<!-- retrieve the latest articles -->
<txp:article_custom month='<txp:variable name="latest" />' form="current_issue_list" />

Offline

#35 2018-11-07 14:44:55

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

Re: [solved] Nth year counter from given start

jakob wrote #315039:

I admit to having got a bit lost here…

Yes, it’s confusing because there are all these terms — issue, current, latest, etc — and they can be interpreted in a dozen different ways. Hard to be clear this way.

it seems a pity (to me at least) that you will eradicate past issues but I also understand your thinking…*

The stories aren’t going anywhere. Only the concept of an ‘Issue’ (except for the current one). And there are no relationships between stories in a given issue, so accessing them individual from the archive loses no meaningful context. If I wanted to do that, have relationships between articles in a given issue (e.g. a subject theme), then I’d probably have to follow more of a TXP model of organization, and I really don’t want that complexity right now.

Use a custom field called issue to hold the issue number of the respective article.

I’m doing this already. This seems like the most fundamental part of the puzzle.

  • Use a combination of sort="issue desc" and if_different to skip all later articles with a different issue number.

I think the problem is that I need to skip all earlier issue articles. The latest issue number is the one I want to make a ‘current issue list’ out of.

If it doesn’t work with if_different, you should be able to set a variable with the first issue number it outputs and then use smd_if to prevent other articles from showing. There’s probably a way to do that with txp:evaluate too.

You just entered the area where my eyes glaze.

Maybe Oleg will post a cleverer alternative ;-)

Hopefully. Yes.

  • Don’t bother with the screen grab as your text is still in Textpattern, so not lost to you,

Yes, I probably won’t keep screen grabs. There’s really no point in having them, unless for legal reasons. I doubt it.

just no longer publicly accessible.

Again, I think you misunderstood. The stories are still there, just not the concept of an ‘issue’.

A PDF or epub format . . .

I’m actually going to be doing epubs of the bigger, researched stuff. And those annotated versions will be sold. It’s too much to explain here, but it will be clear later. ;) In short, there will be plenty to read, but I do need to buy socks too.

I had to look quite hard to find your two past articles on textpattern building blocks and semantics_

You found those? I was not planning to republish those. I read them a while ago and they just sounded really outdated against the state of play today.

I’m staring a clean slate, and none if it is really about Txp, at least not like those two before… More in side reference or whatever to other main subjects. ;)

Offline

#36 2018-11-07 14:56:17

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

Re: [solved] Nth year counter from given start

Destry wrote #315043:

The stories aren’t going anywhere. Only the concept of an ‘Issue’ (except for the current one).

I have a feeling this is going to end up being a big bugaboo for readers later. ‘Where’s issue number blah, blah, blah?!

We’ll see. I won’t be answering such email. ;)

If it even becomes a problem, I could probably make a generic ‘issues archive’ page where stories/articles are group-listed by their issue IDs. That would probably be easier than setting up TXP mag architecture just to slap past collections around.

Offline

Board footer

Powered by FluxBB