Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: How can I create article lists from custom fields?
It happens with alarming regularity to me, haha. If I deleted all my ill-informed advice from the forum, I’d probably have a third fewer posts overall :)
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
Re: How can I create article lists from custom fields?
We were slating 4.8.8 for November to coincide with the planned PHP 8.1 release, while we do some 4.9 work over the summer. But it might come forward if we have a sufficient feature set before then.
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
Re: How can I create article lists from custom fields?
Bloke wrote #330917:
It happens with alarming regularity to me, haha. If I deleted all my ill-informed advice from the forum, I’d probably have a third fewer posts overall :)
I think you are doing fine! You have been a tremendous help more times than I can remember.
Bloke wrote #330918:
We were slating 4.8.8 for November to coincide with the planned PHP 8.1 release, while we do some 4.9 work over the summer. But it might come forward if we have a sufficient feature set before then.
Oh, that sounds great. I may just wait with the Other option until 4.8.8 comes out, then. Much better to do it with something that is part of the core.
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
FWIW, the main question is how to transform a string into multiple values array. The standard txp separator (i.e. comma) is fine for cf names, but not for their values. For example, if location="Tokyo, Kyoto" can be considered as location="Tokyo" OR location="Kyoto", the same logic would fail for movie="Paris, Texas".
In cf branch, separators will be part of cf definitions, so this ambiguity will be gone. Meanwhile, even in 4.8.8 you’ll need to cheat, I’m afraid.
Offline
Re: How can I create article lists from custom fields?
etc wrote #330921:
FWIW, the main question is how to transform a string into multiple values array. The standard txp separator (i.e. comma) is fine for cf names, but not for their values. For example, if
location="Tokyo, Kyoto"can be considered aslocation="Tokyo" OR location="Kyoto", the same logic would fail formovie="Paris, Texas".In cf branch, separators will be part of cf definitions, so this ambiguity will be gone. Meanwhile, even in 4.8.8 you’ll need to cheat, I’m afraid.
Thanks for the additional explanation, Oleg!
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
Oleg, if separators will be part of cf definitions, will it be possible to add the term Other to a city name (eg.: “Other,Okayama” if the separator is a comma, or perhaps “Other|Okayama” or “Other:Okayama” if the separator is a vertical slash or colon) and still have that article appear in the results of https://www.oldphotosjapan.com/photos/?location=Other?
If so, I would only need to remove “Other,” (or “Other|” or “Other:”) from the string when displaying the city name in the article.
It would be a much more elegant solution.
Last edited by Kjeld (2021-07-07 15:45:02)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
Another solution is to just add Other in the location custom field and create an additional custom field for the actual place name of an article with an Other location…
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
I have a question about Oleg’s first suggestion:
etc wrote #330787:
Constructing the list is easy:
<txp:article_custom location fields="location" limit="999" wraptag="ul" break>...
This code outputs all the articles. Because the same city appears in the custom field of several articles, I end up with a list of multiple articles for each city.
I need a custom field list where each city appears only once.
I have tried different approaches, but I can’t quite figure it out…
For example, I tried this:
<txp:article_custom location field="location" limit="999" sort="custom_5 asc" wraptag="ul" break>
<txp:if_different>
<a href="<txp:site_url />location/<txp:custom_field name="location" />"><txp:custom_field name="location" /></a>
</txp:if_different>
</txp:article_custom>
But then I get empty lines between each city name…
How can I make a list with each city appearing only once?
UPDATE: SOLVED
I made a mistake and typed field instead of fields …
This worked:
<txp:article_custom location fields="location" limit="999" sort="custom_5 asc" break="br">
<a href="<txp:site_url />photos/?location =<txp:custom_field name="location" />"><txp:custom_field name="location" /></a>
</txp:article_custom>
I guess the s in fields makes all the difference?
Last edited by Kjeld (2021-07-10 10:21:21)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
Kjeld wrote #330955:
This worked:
<txp:article_custom location fields="location" limit="999" sort="custom_5 asc" break="br">...I guess the
sinfieldsmakes all the difference?
Ahem, what is the difference?
Offline
Re: How can I create article lists from custom fields?
etc wrote #330957:
Ahem, what is the difference?
You used fields, I didn’t. I actually thought you mistyped, so typed field (see my example) … 😅
QUESTION
<txp:article_custom features location and fields="location".
I am probably obtuse, but I can’t seem to find any explanations in the Tag reference index for these two attributes.
Can you explain what they do, how they work, and the difference between fields and field.
Last edited by Kjeld (2021-07-10 10:19:56)
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
Kjeld wrote #330959:
I am probably obtuse, but I can’t seem to find any explanations in the Tag reference index for these two attributes.
I would certainly bet on the lack of docs :-)
Can you explain what they do, how they work, and the difference between
fieldsandfield.
The valueless location filters out the eventual articles with empty location cf, so you don’t get an empty entry in your menu. And fields="location" means ‘extract only different locations’, so
- there is no duplicates in your menu;
- other article fields are not retrieved from db at all, thus saving memory.
Please feel free to ask questions and, even better, complete the docs.
Offline
Re: How can I create article lists from custom fields?
etc wrote #330960:
I would certainly bet on the lack of docs :-)
The valueless
locationfilters out the eventual articles with emptylocationcf, so you don’t get an empty entry in your menu. Andfields="location"means ‘extract only different locations’, so
- there is no duplicates in your menu;
- other article fields are not retrieved from db at all, thus saving memory.
Please feel free to ask questions and, even better, complete the docs.
Thank you.
I wasn’t aware that people who are not in the core team can complete the docs… I am not sure if I know Textpattern well enough, but I will keep my eyes open. Do I have to register somewhere if I find something missing?
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Offline
Re: How can I create article lists from custom fields?
etc wrote #330962:
Thanks! I think you just need a Github account to submit pull requests to docs repo.
Thanks, Oleg.
Github still mystifies and intimidates me… Over the next few weeks, I shall try my best to understand how it all works.
• Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
• MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
• JapaneseStreets.com – Japanese street fashion (mostly txp)
Offline
Re: How can I create article lists from custom fields?
You need very little to submit a request on Github site, especially to complete an existing file.
Offline