Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-01-23 13:29:20

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Alphabetical navigation bar for article lists

Hi,

Is there a plugin or method to create an alphabetical navigation bar at the top of a (long) list of articles in a section (which are sorted by title) so users could easily jump down the page to to articles with titles beginning with a, b, c etc.

Also, if it could only display the alphabetical character in that navigation bar if there are actually articles that start with that character.

Had a quick scour through the forums and could not find anything on this subject.
Thanks,
Phil

Last edited by philwareham (2010-01-23 13:29:31)

Offline

#2 2010-01-23 14:25:48

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Alphabetical navigation bar for article lists

The most automated way I can think of is to use rvm_substr. The only problem is that <txp:rvm_substr length="1"><txp:title /></txp:rvm_substr> will display A…, but I think it won’t be too difficult to remove the ellipsis from the plugin code.
Example code:

<txp:article_custom sort="title asc" limit="999" wraptag="ul" break="li">
   <txp:if_different>
      <a href="#<txp:rvm_substr length="1"><txp:title /></txp:rvm_substr>"><txp:rvm_substr length="1"><txp:title /></txp:rvm_substr></a>
   </txp:if_different>
</txp:article_custom>

<txp:article_custom sort="title asc" limit="999">
   <txp:if_different>
      <h3 id="<txp:rvm_substr length="1"><txp:title /></txp:rvm_substr>"><txp:rvm_substr length="1"><txp:title /></txp:rvm_substr></h3>
   </txp:if_different>
   <txp:permlink><txp:title /></txp:permlink><br />
</txp:article_custom>

Another method would be to use a category or a custom field to store the character. Pro: you can choose to omit words like ‘the’, ‘a’ etcetera. Con: you have to remember to manually fill one more field when writing the article. You’d have to sort the articles by category or custom field rather than by title if you use this method (e.g. sort="custom_1 asc, title asc"), and adapt the tags in the code example above.

Offline

#3 2010-01-23 15:43:52

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Alphabetical navigation bar for article lists

Thanks Els, I used the custom_field solution you suggested in the end.

Offline

#4 2010-01-23 16:54:10

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Alphabetical navigation bar for article lists

One more question if I may, the alpha navigation list now displays only the linked characters for articles that actually appear in the results, which is fine and dandy and what I originally asked for (for example it shows A E D H K). But is there a way of showing all the other alphabet characters as well in that alpha list (but unlinked of course) as in hindsight this currently is not too obvious to end users that it is a navigation system, rather a collect of random letters.

Offline

#5 2010-01-23 23:55:49

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

Re: Alphabetical navigation bar for article lists

Generating list of used letters, and puts them into variables. Variable is named using the letter.

<txp:article_custom sort="custom_1 asc" limit="999">
	<txp:if_different>
		<txp:variable name='<txp:custom_field name="letter" />'  value="is" />
	</txp:if_different>
</txp:article_custom>

Then we output the list of letters and link those that have friends.

<txp:rah_repeat values="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" wraptag="ul" break="li">
	<txp:if_variable name='<txp:rah_repeat_value />' value="is">
		<a href="#<txp:rah_repeat_value />">
			<txp:rah_repeat_value />
		</a>
	<txp:else />
		<txp:rah_repeat_value />
	</txp:if_variable>
</txp:rah_repeat>

Maybe that does it, who knows. No rah_repeats were harmed during posting.

Last edited by Gocom (2010-01-23 23:57:21)

Offline

#6 2010-01-24 17:16:59

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Alphabetical navigation bar for article lists

Thanks a lot Jukka, got that working perfectly as intended now using your method.
Just a minor note in case anyone is using this thread for reference in future, there is a slight error in the second part of above code. It should read…

<txp:rah_repeat value="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" wraptag="ul" break="li">

Had an erroneous ‘s’ on value=

Thanks all,
Phil

Offline

#7 2010-01-25 11:59:21

simoin
Member
From: Ireland
Registered: 2009-02-10
Posts: 50
Website

Re: Alphabetical navigation bar for article lists

This is just what I’m looking for as it would be great way to show an a to z of accommodation providers for a community website,

however I’m getting this error,

Tag error: <txp:variable name='<txp:custom_field name="letter" />' value="is" /> -> Textpattern Notice: variable_name_empty on line 3718

I am using the plugin glz_custom_fields and have set up a custom field, custom_12 called “letter”

I have used the code exactly as above, and placed it in a form, any help much appreciated.

Offline

#8 2010-01-25 12:24:50

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Alphabetical navigation bar for article lists

The way I did it was…

1. Install rah_repeats plugin.
2. Set up a custom field (in your case custom_12) with a name of ‘letter’, then manually add the first letter of the article title in that custom_field for every required article.
3. Add this code into the article form I use for displaying stickies:

<txp:article_custom sort="custom_12 asc" limit="999">
<txp:if_different>
<txp:variable name='<txp:custom_field name="letter" />' value="is" />
</txp:if_different>
</txp:article_custom>

<txp:rah_repeat value="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" wraptag="ul" break="li">
<txp:if_variable name='<txp:rah_repeat_value />' value="is">
<a href="#<txp:rah_repeat_value />"><txp:rah_repeat_value /></a>
<txp:else />
<txp:rah_repeat_value />
</txp:if_variable>
</txp:rah_repeat>

<txp:article_custom sort="custom_12 asc, title asc" limit="999">
<txp:if_different>
<a name="<txp:custom_field name='letter' />"></a>
</txp:if_different>
<txp:permlink><txp:title /></txp:permlink />
</txp:if_article_category></txp:article_custom>

Hope that helps. You will need to style your alpha list of course using css, put a class on this line for example…

<txp:rah_repeat value="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" wraptag="ul" break="li" class="alpha-links">

CSS example…

ul.alpha-links{
	list-style:none;
        text-transform:uppercase;
	margin-bottom:20px;
}
ul.alpha-links li{
	list-style:none;
        float:left;
        background-color:#ccc;
        padding:3px;
        margin-right:2px;
}

Phil

Last edited by philwareham (2010-01-25 12:41:32)

Offline

#9 2010-01-25 12:31:49

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Alphabetical navigation bar for article lists

simoin wrote:

Tag error: <txp:variable name='<txp:custom_field name="letter" />' value="is" /> -> Textpattern Notice: variable_name_empty on line 3718

Probably you have an article for which the “letter” custom field is blank.

Somewhere I thought there was a plugin that would sort articles by title, but putting any initial article at the end (as in: Brief History of Time, A). That would obviate the need for the custom field. But I can’t find any such plugin. I suppose I could add such a feature to soo_article_filter.


Code is topiary

Offline

#10 2010-01-25 14:34:36

simoin
Member
From: Ireland
Registered: 2009-02-10
Posts: 50
Website

Re: Alphabetical navigation bar for article lists

Thanks for your help jsoo and Phil, I’ll have another go at this,
I appreciate the help,

Simon

Offline

Board footer

Powered by FluxBB