Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Alphabetical list of articles in a section
jakob wrote #320941:
Thanks for the pointer. So:
substr($string, 0, 1)
is the php function and would need registering in the advanced options in the Admin › Preferences. TRUEsubstring(string, 1, 1)
is an XPath function and, I guess, does not need registering. TRUE- And the
UPPER
insort="UPPER(Title)"
is MySQL. Used only for sort, not needed if all articles titles start uppercased (or all lowercased).
You showed another example of that not all that long ago. It does requires quite a few forms, though you did mention in the past that simpler
breakby
expressions can go straight into the attribute.
Yes, you could go with
breakby="<txp:evaluate query='substring(<txp:title escape=''quote'' />, 1, 1)' escape='upper' />"
to spare a db form query. You should also be able (untested) to replace <txp:yield item="breakby" />
in alphaform
with
<txp:evaluate query='substring(<txp:title escape="quote" />, 1, 1)' escape="upper" />
and use alphaform
as both breakby
and breakform
attributes. It’s a readability/modularity question.
Offline
Re: Alphabetical list of articles in a section
Honestly, these threads are better than TED talks. I learn so much.
Offline
Offline
Re: Alphabetical list of articles in a section
BTW, we could add first
to available escape
values. Or even consider integer values as substring length:
<txp:variable name="hello" value="welcome" />
<txp:variable name="hello" escape="3" /> <!-- outputs 'wel' -->
<txp:variable name="hello" escape="-2" /> <!-- outputs 'me' or 'lcome' or 'welco'? -->
Offline
Re: Alphabetical list of articles in a section
Oooh interesting. If we’re going that way and it’s not going to clash with anything else…
<txp:variable name="hello" value="welcome" />
<txp:variable name="hello" escape="3" /> <!-- outputs 'wel' -->
<txp:variable name="hello" escape="3,4" /> <!-- outputs 'lcom'? -->
<txp:variable name="hello" escape="-2" /> <!-- outputs 'me'? -->
<txp:variable name="hello" escape="5,-2" /> <!-- outputs 'co'? -->
<txp:variable name="hello" escape="-5,4" /> <!-- outputs 'lcom'? -->
The only thing with using the from,count
syntax is that it differs from PHP’s substr()
insofar as it starts from 1 and not 0, for consistency with the single count
syntax. That might confuse programmers at first, but everyone else should get it.
EDIT: not really sure if ‘escape’ is the right terminology though. If we’re doing this, shouldn’t we introduce a new global attribute? I’d suggest expanding trim
(since we’re trimming the text by a number of characters) except it’s currently used to trim alphanumerics, and an integer is a valid character you might want to strip off.
Last edited by Bloke (2020-01-08 22:23:02)
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
Online
Re: Alphabetical list of articles in a section
Oleg, that is some superb tag-fu you are displaying. Splendid.
I’m trying hard to understand – taking notes along with the URL of the thread to test and analyse once I am past the first strong cold of the year (ginger tea with the last of the yuzu).
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
Offline
Re: Alphabetical list of articles in a section
phiw13 wrote #320957:
(ginger tea with the last of the yuzu).
Yum…
Bloke wrote #320953:
not really sure if ‘escape’ is the right terminology though. If we’re doing this, shouldn’t we introduce a new global attribute? I’d suggest expanding
trim
(since we’re trimming the text by a number of characters) except it’s currently used to trim alphanumerics, and an integer is a valid character you might want to strip off.
Yep, escape
will not do since comma is used as separator there. We could adopt 1%%9
syntax used in custom fields filter, and trim
suits better indeed. But I’m not sure we need it in such a generality: extracting/removing 3 first letters can be useful on plugins/themes sites, but other cases look exotic.
Offline
Re: Alphabetical list of articles in a section
etc wrote #320960:
Yep,
escape
will not do since comma is used as separator there.
Ah of course. If you think escape
with an integer just for removing everything but the given N letters is worthwhile, by all means stick it 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
Online