Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-03-23 22:40:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Article sort by category confusion

I’m a little baffled. Trying to sort out an issue with smd_horizon has led me to some interesting test cases. I’m sure I’m just being a mollusc here so please can someone either corroborate my findings or tell me where I’m going wrong.

Steps to success:

1: Txp 4.5.7, vanilla, delete Welcome article.
2: Set up/alter three categories: Cats, Dogs and Badgers.
3: Set up a bunch of articles assigned to these categories randomly. In my case I have this:

Title url_title cat1 cat2
Art 1 art_1 Dogs
Art 2 art_2 Cats
Art 3 art_3 Badgers Dogs
Art 4 art_4 Badgers
Art 5 art_5 Cats
Art 6 bart_6 Dogs Cats
Art 7 art_7 Badgers Cats
Art 8 art_8 Dogs Badgers

4: After setting them up, edit Art 5 and save it, to alter its LastMod time.
5: On the public side, pick an article and step through Prev/Next in either direction to confirm they are in Posted order.
6: In your archive Page template, change the individual <txp:article> tag by adding the sort="LastMod"> attribute.
7: Repeat Step 5 and confirm that Art 5 appears last when stepping next/prev.
8: Alter the archive Page template’s individual article sort order to sort="url_title".
9: Repeat Step 5 and confirm that Art 6 now occurs last in the list when stepping through the articles, because its url_title starts with ‘b’.
10: Alter the archive Page template’s individual article sort order to sort="Category1" (capital C as per the docs).
11: Repeat Step 5 and confirm that… wtf?

In my test case:

  • If I start on Art 3, I expect the next article with Badgers as its category 1 to be Art 4. But the Next link leads to Art 6 (linking Art3:category2 to Art6:category1, maybe?), while the Prev is greyed out (as expected).
  • If I start on Art 5, I expect the previous article with Cats as its category 1 to be Art 2, but it takes me to Art 8. At this point, Next does not return me to Art 5 where I just came from, but to Art 1 instead :-s The Prev link takes me to Art 6 as expected, but the Prev after that takes me to Art 3 instead.

A similar story happens if sort="Category2".

In my PHP-d out brain, have I fundamentally misunderstood something about the way article sorting by category works? Is my logic flawed? Is Textpattern not geared up to do this and I should be using <txp:article_custom> instead? Or do we still have a bug in the link_to_next code?

Please put me out of my misery one way or the other. Thanks in advance.


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

#2 2015-03-24 06:23:24

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: Article sort by category confusion

I’ll try to add some hints on how to diagnose these issues:

While in debug mode, the tag trace contains at least one occurrence of the term filterAtts, usually on a line saying [filterAtts accepted].

This indicates that the preceding txp:article / txp:article_custom tag established a sorting order which should be obeyed by any subsequent link_to_next / link_to_prev tags.

If you happen to find more than one line containing the term filterAtts you scent trouble in need of further investigation.

Offline

#3 2015-03-24 09:18:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Article sort by category confusion

Thanks for the hints, I’ll run through the debug output later. Would be interesting to find out if anyone else can replicate this. Presumably I’m not trying to do anything it’s not designed to do?

P.S. appears to be working ok in 4.6-dev as far as I can tell.

Last edited by Bloke (2015-03-24 09:26:09)


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

#4 2015-03-24 22:51:15

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Article sort by category confusion

Stef, I ran through your steps on a test install here and I’m seeing something screwy as of step 7. You want info here, or should I email you?

Actually, no. Ignore that. My bad.

Last edited by gaekwad (2015-03-24 22:52:12)

Offline

#5 2015-03-25 15:17:55

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Article sort by category confusion

gaekwad wrote #289360:

Actually, no. Ignore that. My bad.

Thanks for trying it out. So does that mean category sorting and stepping is working fine for you, and it’s just my 4.5.7 installation or the plugin?


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

#6 2015-03-25 17:36:37

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Article sort by category confusion

Read: it was late and I got confused – sort order was not what I was expecting. Will try again with new install and fresh(er) eyes.

When a sort attribute is set without asc or desc, does it assume the default?

Offline

#7 2015-03-25 21:50:00

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Article sort by category confusion

OK, I tried this again with a fresh install and not-so-fresh eyes.

Steps 1 through 4 complete. Database looks like this:

INSERT INTO `scratchtextpattern` (`ID`, `Posted`, `Expires`, `AuthorID`, `LastMod`, `LastModID`, `Title`, `Title_html`, `Body`, `Body_html`, `Excerpt`, `Excerpt_html`, `Image`, `Category1`, `Category2`, `Annotate`, `AnnotateInvite`, `comments_count`, `Status`, `textile_body`, `textile_excerpt`, `Section`, `override_form`, `Keywords`, `url_title`, `custom_1`, `custom_2`, `custom_3`, `custom_4`, `custom_5`, `custom_6`, `custom_7`, `custom_8`, `custom_9`, `custom_10`, `uid`, `feed_time`)
VALUES
	(2,'2015-03-24 06:00:00','0000-00-00 00:00:00','scratch','2015-03-24 06:00:00','scratch','Art 1','','','','','','','dogs','',0,'Comment',0,4,1,1,'articles','','','art-1','','','','','','','','','','','73a6c39f63f1a1e7722e6584c8875ac3','2015-03-24'),
	(3,'2015-03-24 07:00:00','0000-00-00 00:00:00','scratch','2015-03-24 07:00:00','scratch','Art 2','','','','','','','cats','',0,'Comment',0,4,1,1,'articles','','','art-2','','','','','','','','','','','36e470bb0d14b33e411c8861b2c5f204','2015-03-24'),
	(4,'2015-03-24 08:00:00','0000-00-00 00:00:00','scratch','2015-03-24 08:00:00','scratch','Art 3','','','','','','','badgers','dogs',0,'Comment',0,4,1,1,'articles','','','art-3','','','','','','','','','','','91f4d361dce067ac63ea2c2f7d84936f','2015-03-24'),
	(5,'2015-03-24 09:00:00','0000-00-00 00:00:00','scratch','2015-03-24 09:00:00','scratch','Art 4','','','','','','','badgers','',0,'Comment',0,4,1,1,'articles','','','art-4','','','','','','','','','','','d0cc08e2917382e029478adf80ed6cea','2015-03-24'),
	(6,'2015-03-24 10:00:00','0000-00-00 00:00:00','scratch','2015-03-24 14:00:00','scratch','Art 5','','','','','','','cats','',0,'Comment',0,4,1,1,'articles','','','art-5','','','','','','','','','','','f90e17d26e69f0a5872784a40274f2fd','2015-03-24'),
	(7,'2015-03-24 11:00:00','0000-00-00 00:00:00','scratch','2015-03-24 11:00:00','scratch','Art 6','','','','','','','dogs','cats',0,'Comment',0,4,1,1,'articles','','','bart-6','','','','','','','','','','','211bce804f8b320a669343f32b8e7997','2015-03-24'),
	(8,'2015-03-24 12:00:00','0000-00-00 00:00:00','scratch','2015-03-24 12:00:00','scratch','Art 7','','','','','','','badgers','cats',0,'Comment',0,4,1,1,'articles','','','art-7','','','','','','','','','','','dde4d479b7de68d87a9978f66355251a','2015-03-24'),
	(9,'2015-03-24 13:00:00','0000-00-00 00:00:00','scratch','2015-03-24 13:00:00','scratch','Art 8','','','','','','','dogs','badgers',0,'Comment',0,4,1,1,'articles','','','art-8','','','','','','','','','','','50bb8711e0a8197eaa8df1f0dcf03a61','2015-03-24');

In the posted context, art-1 is oldest, art-8 is newest, inner articles are spaced 1 hour apart, so this is the sort order in the admin-side (oldest first):

  • art-1
  • art-2
  • art-3
  • art-4
  • art-5
  • bart-6
  • art-7
  • art-8

Moving to modified sorting, art-1 is oldest, art-5 is newest. Admin-side sort order (oldest first):

  • art-1
  • art-2
  • art-3
  • art-4
  • bart-6
  • art-7
  • art-8
  • art-5

Step 5 – confirming my article tag looks like this:

       <txp:article listform="article_listing" limit="5" sort="LastMod" />

In the absence of asc or desc, I would expect sort="LastMod" to inherit the default of desc (article defaults to Posted desc, search results default to score desc). It doesn’t, though – LastMod effectively becomes LastMod asc. Viewing ?s=articles with sort="LastMod" gives me this sort order:

  • art-1
  • art-2
  • art-3
  • art-4
  • bart-6 (older link after this article)
  • art-7
  • art-8
  • art-5

…and on that basis I would expect to click on art-1 and use ‘Older’ to navigate through; art-1 (6am), and clicking Older takes me to art-2 (7am – newer than art-1). ‘Older’ isn’t totally accurate, but within the confines of LastMod asc sorting it does tally up.

Or does it? Now I’m confused – is asc oldest first as the timestamp increases (smallest first, Epoch time-stylee) or newest first because the relative post age is smaller? Huh.

Anyway, setting sort="LastMod asc" has a similar sort order as sort="LastMod" so I’ll assume that’s expected behaviour.

Step 7: confirmed.
Step 9: confirmed.

Using sort="Category1" gives me this order on the front-side:

  • art-3
  • art-4
  • art-7
  • art-2
  • art-5 (older link after this article)
  • art-1
  • bart-6
  • art-8

Explicitly using sort="Category1 asc" gives me the same order, as does sort="category1 asc" and sort="category1". To follow your test case, I also start with art-3. Clicking ‘Older’ takes me to art-2. ‘Older’ in art-2 takes me to art-1. ‘Older’ is greyed out on art-1.

So, yeah. Diags and/or tag trace and/or screencast any good to you, Stef?

Offline

#8 2015-03-26 00:15:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Article sort by category confusion

Thanks for testing, Pete.

‘Older’ isn’t totally accurate, but within the confines of LastMod asc sorting it does tally up.

Yeah, older and newer do break in semantics if mucking around with sort order. And yes, it seems to default to asc if you don’t explicitly set it, which is the opposite of the default if you don’t specify anything. But the only reason it’s desc by default is so that new content shows first, for convenience. If you’re overriding it with anything, then I guess the implication is that sort order must be stated. Kinda backwards in a way, but understandable I s’pose.

Using sort="Category1" gives me this order on the front-side: <snip>

Exactly as expected, ordered by category1 name: Badger Badger Badger Cat Cat Dog, etc — damn, should have chosen Mushroom and Snaaaaaaaake for comedy value :-D

Ahem, moving on…

To follow your test case, I also start with art-3. Clicking ‘Older’ takes me to art-2. ‘Older’ in art-2 takes me to art-1. ‘Older’ is greyed out on art-1.

Which is wrong in my eyes. When sorting by category1, the “oldest” is art-3 so the Older link should be greyed out and Newer should go to art-4, then art-7, then art-2

I checked my tag trace in debug mode and there are two instances of the filterAtts that Robert mentioned. First is accepted for the main article, the second is ignored when loading <txp:article form="comments_display" />. “Aha”, I thought. Maybe loading the second article inside the first is screwing things up. So I removed the call to the comments_display form… but it made no difference. The sort order when stepping through articles one by one was still screwy.

[ On a tangent, calling an article from inside an article seems a bit wrong to me. It should probably be <txp:output_form form="comments_display" /> instead, but this is something I’ll take up with Phil if it does indeed turn out to be posing problems. ]

So now I’m a bit confuddled. It does appear that the article thinks it has a sort order. The article list gets it right, but when in individual article mode, stepping through the articles seems to default to Posted(ish) order, regardless of the article’s sort attribute. The ‘ish’ is because it either stops when it reaches some endpoint, or loops back to another article, at which point you cannot return to the article you came from by using the opposite link. The logic behind how it’s determining this sequence, I’ve yet to fathom.

Anyone who wants to test this and provide any pointers or ideas on what it’s doing exactly, postulating as to where it’s fouling up would be most welcome. Potential fixes or test cases where it does work (perhaps with a simpler page template?) also appreciated. It’s doing my head in.


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

#9 2015-03-26 09:11:27

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

Re: Article sort by category confusion

That’s a bug/feature, <txp:link_to_next/prev /> looks for a value strictly greater/less than the current one, thus skipping identical ones.

Last edited by etc (2015-03-26 09:27:35)

Offline

#10 2015-03-26 09:29:32

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: Article sort by category confusion

etc wrote #289432:

That’s a bug

That’s a feature:

The sort column must contain distinct values (e.g. 1, 2, 4, 7, 99; not 1, 2, 2, 2, 2, 2, 4, 7, 99). Otherwise, the next/prev links will choose one arbitrary neighbour with a lower/higher value.

Offline

#11 2015-03-26 09:36:41

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

Re: Article sort by category confusion

In reply to wet #289434:

That’s a feature

that’s what I’ve said to myself five minutes after posting. Well, that’s the explanation.

Offline

#12 2015-03-26 09:43:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

Re: Article sort by category confusion

In reply to wet #289434:

That’s a feature

Can it just become a feature for numeric values only and leave text-based sorting values to order by the selected sort column, plus date for disambiguation using the sort direction from the desired sort column? Or does that open a whole world of hurt?


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