Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Limit amount of links produced by txp:Category_List
Hello,
How can i get the category list to limit to say 20 links?
Many Thanks,
Jonathan
Offline
Re: Limit amount of links produced by txp:Category_List
the category_list tag outputs a list of all your categories (ha!!) You can exclude some of them, or get only article categories, etc. See the TextBook, but contrary to the article tag it has no “limit” attribute.
You may want to check if any of the category plugins at Textpattern Resources does what you want.
Offline
#3 2009-05-22 11:40:01
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: Limit amount of links produced by txp:Category_List
If you have a minimal mysql knowledge try smd_query
Offline
Re: Limit amount of links produced by txp:Category_List
You could also set up some a counter (look at adi_calc or aks_var plugins), and then check the value for the counter (using txp:if_variable or smd_if plugin). If it’s equal or above 20, stop outputting categories.
It’s the poor man’s limit.
Offline
Re: Limit amount of links produced by txp:Category_List
That sounds like a good idea do you know how i’d go about doing that?
Offline
Re: Limit amount of links produced by txp:Category_List
classcreative
The smd_query route is shorter, though you do lose some of the niceties of the category_list tag, such as active category:
<txp:smd_query query="select name, title from txp_category where type='article' and name not in ('default', 'root') order by name asc limit 20" break="li" wraptag="ul">
<a href="/category/{name}">{title}</a>
</txp:smd_query>
That’s untested but will get you close. You could of course put smd_if (or equivalent) inside the container to detect the current category and set a class on the anchor.
maniqui’s suggestion is more involved but may allow you to do more. It really depends on why you only want to see the 1st 20 categories… are the rest of them no use in your design?!
Last edited by Bloke (2009-05-22 14:03:58)
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
Offline
Re: Limit amount of links produced by txp:Category_List
Ok, Thank you I’ll give that a go.
I was only going to display 10-20 in order to use the sort=“rand()” to produce a random list of 20 or so categories. As I’m thinking there are going to be a large number of categories in the blog it would have made a huge list.
Offline
Re: Limit amount of links produced by txp:Category_List
worked like a charm! Just added order by rand() to get exactly what i wanted.
Thanks for your help guys
Offline