Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-11-05 11:42:51

Whitingx
Member
Registered: 2005-02-04
Posts: 11
Website

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

#2 2007-11-05 11:51:23

iblastoff
Plugin Author
From: Toronto
Registered: 2006-06-11
Posts: 1,197
Website

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

#4 2007-11-05 14:23:33

Whitingx
Member
Registered: 2005-02-04
Posts: 11
Website

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

#5 2007-11-05 14:34:03

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#6 2007-11-05 14:36:14

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

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

#7 2007-11-05 15:05:58

Whitingx
Member
Registered: 2005-02-04
Posts: 11
Website

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

#8 2007-11-05 20:27:01

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

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

#9 2007-11-06 09:28:11

Whitingx
Member
Registered: 2005-02-04
Posts: 11
Website

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

#10 2007-11-06 14:31:55

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

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

#12 2007-11-06 21:25:41

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

Board footer

Powered by FluxBB