Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-01-05 12:31:05
- psimsy
- Member
- From: Londinium
- Registered: 2004-12-27
- Posts: 13
Category list. Linking and non-linking
I am trying to get txp to display a list of ALL categories, but only link to categories that have articles assigned to them. So the list can grow with the addition of new categories and then become linked to content when it is created.
I have looked at hacking plugins (like azp_menugen) and trying to use conditionals but not had much luck..
Any ideas would be gratefully received.
p_
Offline
Re: Category list. Linking and non-linking
The built-in tag category_list with some conditional cleverness might help — and one of the tag gurus might well have answered this before or know of a really cool native solution.
Failing that, do the adi_cat_menu or cbs_category_list plugins get you anywhere?
Last edited by Bloke (2009-01-05 12:40:52)
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
#3 2009-01-05 15:34:10
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Category list. Linking and non-linking
Bloke wrote:
— and one of the tag gurus might well have answered this before or know of a really cool native solution.
Did I hear my name? ;)
<txp:category_list wraptag="ul" break="li">
<txp:variable name="hasarticles" value='<txp:article_custom category=''<txp:category />'' limit="1" />' />
<txp:if_variable name="hasarticles" value="">
<txp:category title="1" />
<txp:else />
<txp:category title="1" link="1" />
</txp:if_variable>
</txp:category_list>
Last edited by els (2009-01-05 15:35:50)
Offline
Re: Category list. Linking and non-linking
Genius! You tag fiend, you ;-)
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: Category list. Linking and non-linking
wow. i’m very very very slowly starting to grasp the possibilities that txp:variable gives!
~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~
Offline
#6 2009-01-06 10:48:00
- psimsy
- Member
- From: Londinium
- Registered: 2004-12-27
- Posts: 13
Re: Category list. Linking and non-linking
Hi. Thank you for the great help. For the sake of anyone else that needs this I am posting some extra how to use info.
I put code in a form and called the form into a page. It didn’t seem to work called from an article.
Here is the slightly hacked version I used to for my purposes. Since <txp:category_list>
doesn’t nest the categories, I had to break up the list into the multiple category chunks I needed and put them all in the form. This is a bit bulky and non-DRY and I am sure there is a better way out there.
I am concerned that with the addition of <txp:variable>
which seems amazingly powerful we are going to lose the simplicity of the tag & plugin relationship. But i expect this discussion is raging elsewhere.
Thanks for your help.
p_
<txp:category_list wraptag="ul" break="li" parent="health" children="0" class="list" exclude="health" >
<txp:variable name="hasarticles" value='<txp:article_custom section="articles" category=''<txp:category />'' limit="1" />' />
<txp:if_variable name="hasarticles" value="">
<txp:category title="1" />
<txp:else />
<a href="articles/<txp:category />"><txp:category title="1" /></a>
</txp:if_variable>
</txp:category_list>
Offline
#7 2009-08-28 11:59:36
- txpnisti
- Member
- Registered: 2009-02-25
- Posts: 23
Re: Category list. Linking and non-linking
I found the orignal code above yesterday, it solves nicely the problem listing only used categories even on MLP-site like I have. But why it adds so much queries? When looking the source debug mode on, without this I have 25 queries on page, and when this is activated there is 70. Isn’t that little bit too much? Is there a workaround to reduce the amount?
It doesn’t seem to affect loading time but I’m currently the only one visiting the site under development. I’m not sure if that is too much when there is lots of visitors browsing?
Offline
Re: Category list. Linking and non-linking
This is really useful, thanks Els for your TXP tag genius
Admin Themes Prometheus | Stung | <txp:coder/
My Portfolio | ɹǝpuɐz.com | @MrMartineau
<txp:coder /> – Convert your designs into Textpattern-based websites
jQuery Style | @jquerystyle
Offline