Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Filter articles by letter
I’m trying to put together an A-Z listing, is it possible to filter articles by title ?
If there is no easy way to do this in Textpattern via a tag or plugin, does anyone have any pointers to how to do this using PHP ?
Thanks for any help you can give.
Offline
Re: Filter articles by letter
are you looking for <txp:article sort="Title" />
? additionally you could use sort="Title asc"
or sort="Title desc"
and such depending on what order you want. Here is a full list of attributes for txp:article
for the article list, Older/newer links should work correctly as well. If you want individual prev/next links within the article, you’d have to use jk_neighbour or jra_link_to_next & jra_link_to_prev
(i’ve only used jk_neighbour. i’m not really sure how it differs from ra_link_to_next & jra_link_to_prev)
edit: you may have been looking for a solution such as clicking “A” will give you all articles that start with A. in that case, you could probably sort by custom field or just use categories instead.
Last edited by iblastoff (2007-11-05 13:25:11)
Offline
#3 2007-11-05 13:16:46
- ultramega
- Member
- Registered: 2006-02-26
- Posts: 221
Re: Filter articles by letter
I used category1 for alphabets in similar situation. Works usually well, but…
I recently noticed odd thing: I have “-” between some words of article titles. That makes the listing unaccurate as title starting with word like ABC-P… is printed before title starting with ABCJ. Strange.
I couldn’t get jk_neighbour pagination inside articles to work because foreign characters. You propably don’t need them, as you mention only letters from a-z ;) We have expanded character set which reaches ä & ö as the last letters. Lucky you.
Offline
Re: Filter articles by letter
Thanks very much for the help so far.
I’ve taken a look at <txp:custom_field /> but can’t see how you can use this to display only title links starting with A,B,C etc. am I missing something obvious ?
Offline
Re: Filter articles by letter
Whitingx,
Hand-write and specify the letter by yourself as the custom field’s input. And the you could use custom field for ordering the articles, or output the first letter in the list, like with this kind of article form:
We are using custom field named Order and lets name the form as order-list.
<txp:if_different><h2><txp:custom_field name="Order" /></h2></txp:if_different>
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:excerpt />
And lets output the list with <txp:article order="custom_1 asc" limit="30" form="order-list" />
Cheers!
Last edited by Gocom (2007-11-05 14:46:44)
Offline
Re: Filter articles by letter
You will need to manually enter the letter in a custom field and then use article_custom.
A possible method would be
<txp:article_custom customfieldname="value"/>
(replace customfieldname with the name of your custom field and value with a letter of the alphabet.)
I’m also wondering if you could use the above with asy_wondertag and the if_different 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
Re: Filter articles by letter
Great stuff, thanks very much for all the help supplied.
As a final question, does anyone know any PHP magic that can strip the first letter off the article title and add it automatically to the custom field ?
Once again thanks to everyone for the help.
Offline
Re: Filter articles by letter
Could you then not go straight for if_different
first letter of txp:title and dispense with the custom field altogether?
You’d need to use txp:php
to echo the value for title. Runing it through the php function strtolower(substr($string,0));
should give you the first letter of a string in lower case.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Filter articles by letter
Jakob, that sounds promising, please could you expand on your answer.
If I wanted to display a list of all articles beginning with A how would the code look ? Something like ?
<txp:if_different>
<txp:php>
<txp:title />strtolower(substr($string,0));
</txp:php>
</txp:if_different>
How do I specify only titles beginning with certain letters for <txp:title />
?
Thanks once again for all the help given.
Last edited by Whitingx (2007-11-06 10:58:28)
Offline
Re: Filter articles by letter
Really sorry, but no time to try this out in any detail. Some tips to help you on your way – check this article (on using tags in tags but instructive anyway) to see the basic principle of how txp-tags are called from within php. In this case $string needs to be the article title. See also txp:if_different in the textbook for its correct setup (and this weblog entry).
One note: the if_different approach won’t list just the articles beginning with a, it will list all articles interpersed with a, then b, then c, etc. If you set it up as nested ul-lists you can then structure it as you like or make a collapsing menu out of it.
PS: saw this article on an a-z index using categories on an old thread. This is probably an easier way of listing only those with category “a” or category “b” etc. but requires you to assign a category for each article.
TXP Builders – finely-crafted code, design and txp
Offline
#11 2007-11-06 20:32:21
- ultramega
- Member
- Registered: 2006-02-26
- Posts: 221
Re: Filter articles by letter
^ And that’s basically what I’m using too on one site currently. This is all needed to make it roll:
<txp:category_list categories=“a,b,c,j,m,z” />
Every article have been tagged to category representing it’s title’s starting letter.
I keep it up to date “semi-manually”, writing only letters which actually have articles for the “categories” parameter.
Last edited by ultramega (2007-11-06 20:35:23)
Offline
Re: Filter articles by letter
hm. Is it posible to call all articles with title starting from diserable letter? For english it would be great to pass the
and “a” articles :) Like it realised in chh_article_custom
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Pages: 1