Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-22 08:03:05

classcreative
Member
From: Solihull
Registered: 2009-05-22
Posts: 12
Website

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

#2 2009-05-22 10:15:26

jordi
Member
From: Barcelona
Registered: 2005-09-14
Posts: 94
Website

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

#4 2009-05-22 12:04:27

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

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.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#5 2009-05-22 13:23:58

classcreative
Member
From: Solihull
Registered: 2009-05-22
Posts: 12
Website

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

#6 2009-05-22 14:03:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

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

#7 2009-05-22 14:58:55

classcreative
Member
From: Solihull
Registered: 2009-05-22
Posts: 12
Website

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

#8 2009-05-22 15:06:57

classcreative
Member
From: Solihull
Registered: 2009-05-22
Posts: 12
Website

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

Board footer

Powered by FluxBB