Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
category_list
What chance is there of making the <txp:category_list />
tag able to display categories from a specific section? I have the distinct impression it’s been asked for before which is partly why we ended up with the cbs_category_list
plugin. Unfortunately it doesn’t sit well with MLP and I have to deal with a world-wide audience as do most of us that have a business.
Last edited by thebombsite (2010-08-02 14:13:53)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: category_list
thebombsite wrote:
What chance is there of making the
<txp:category_list />
tag able to display categories from a specific section?
I must be missing something. How would you associate categories with a section in the first place? Or do you mean only display categories that have been used in articles that are already assigned to a specific section(?!)
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
Bloke wrote:
Or do you mean only display categories that have been used in articles that are already assigned to a specific section(?!)
Probably, most likely :-)
I don’t really know about that request, well I like it as an idea. If section
attribute gets added to the core as a native feature, ppl might (or will) complain. Not because the feature, it’s great actually in what it brings to the table, but because of the performance. As TXP stores the categories within the articles, the peformance hit would be huge compared to the use of category_list
without section filtering.
I would give it +1, but I don’t really know about the media attractiveness. I give it +1/2?
Last edited by Gocom (2010-08-02 15:41:16)
Offline
Re: category_list
Oh, now you are going all technical on me again Jukka.
Anyway, to illustrate my point, if you go and have a look at this beauty you will see that in the topnav the “blog” and “photo” sections both have a drop-down category list. Can’t do this with native Txp tags so I have to use cbs_category_list
because it is “section-sensitive”. Same goes for the “Select A Category” button which contains both section links and category links all in the right order.
Also if you look at this page you will see that I have 2 category list widgets in the sidebar which again could not be done with the standard <txp:category_list />
tag.
I could go on and point to similar uses in most of the themes. cbs_category_list
has become an indispensable tool which kind of makes me wonder why I can’t do this with the native tag.
But heck, I’m only trying to attract the “one-click” nerds to the best, true CMS available so don’t worry too much about it. I’ll just carry on with the tools at my disposal.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: category_list
thebombsite
So it is only listing categories that are in use in a given section! Riiiight.
In that case, no: the existing tag can’t be used for that because <txp:category_list />
works across category types and sections are article-specific. So adding a section
attribute would restrict the tag to articles only in that specific case, and potentially confuse people who might think it could be used to show file categories from a certain section, which are not actually section-aware. If that makes any sense at all…
cbs_category_list works well and does a specific job that is currently outside the scope of the generic tag. If we had tags like <txp:article_category_list />
, <txp:image_category_list />
, and so on then it would be a different story… and we’d have people complaining that the tags should be consolidated into one tag with a type
attribute :-)
As far as query performance goes it’s probably not all that bad (haven’t thought it through — Gocom might have a better idea on this, hence his concerns). From my rudimentary thoughts, since the category names are actually hard-coded into the textpattern table (at the risk of going all technical, it thus doesn’t adhere to third normal form) it should be possible to just grab all unique category1/category2 FROM textpattern WHERE Section=‘blah’ and it’ll give us the required list. Would need to join it to the category table like Christophe does if you wanted category titles, but that’s a simple JOIN and isn’t that much overhead either. At least, as far as I can tell — I might be wrong as I’ve not tried it.
However, in the event TXP goes to unlimited categories this becomes trickier and involves a lot more tables/joins. Note that cbs_category_list will stop working at that point anyway — or at least not work reliably — so it’ll need updating.
I like the notion and appreciate its usefulness in certain situations but — at least for now — sorry but the one-click nerds will have to make do with installing a plugin for this.
Last edited by Bloke (2010-08-02 22:18:16)
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
OK. I’ll have to give them biscuits or something instead. ;)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: category_list
Hi Stuart
Hopefully, I’ve understood your request correctly.
Let’s begin easy (just TXP markup, almost no HTML markup added):
<txp:category_list break="" wraptag="ul">
<txp:variable name="cat_has_articles_in_this_section"><txp:article_custom section='<txp:section />' category='<txp:category />' limit="1" sort="posted asc"><!-- (avoid querying/processing a form) --></txp:article_custom></txp:variable>
<txp:if_variable name="cat_has_articles_in_this_section" value="">
<txp:else />
<li><txp:category title="1" link="1" /></li>
</txp:if_variable>
</txp:category_list>
This one is current-section-sensitive. That means, when you are browsing section Photos, it will generate a list of all categories on section photos (section='<txp:section />'
) that have at least 1 article on the currently-being-iterated category (that’s all what <txp:category_list />
can do for us).
Then, you could improve over this, in two (or possible more) ways:
- A) by just hardcoding the desired section, instead of making it context-sensitve:
section="photos"
. This will help, for example, on the Contact page you linked, where you just know that you want your widget to list just the photo categories. - B) by wrapping the above code on a
<txp:section_list />
iterator. This could be useful on your main navigation (the one at top), if it’s currently being generated by<txp:section_list />
.
<txp:section_list break="" wraptag="ul">
<txp:if_section name="blog,photos"><!-- if I recall correctly, if_section inside a section_list will test for current iterated section, not for current URL section -->
<li><txp:section title="1" link="1" />
<txp:category_list break="" wraptag="ul">
<txp:variable name="cat_has_articles_in_this_section"><txp:article_custom section='<txp:section />' category='<txp:category />' limit="1" sort="posted asc"><!-- (avoid querying/processing a form) --></txp:article_custom></txp:variable>
<txp:if_variable name="cat_has_articles_in_this_section" value="">
<txp:else />
<li><txp:category title="1" link="1" /></li>
</txp:if_variable>
</txp:category_list>
</li>
<txp:else /><!-- other sections (!= blog,phothos) -->
<li><txp:section title="1" link="1" /></li>
</txp:if_section>
</txp:section_list>
Of course, if you are not generating the main nav by using txp:section_list, then it would be just a matter of use the A technique (hardcoding the section attribute).
Stuart, I’m coding some of this off the top of my head (not all, as this is code I’ve used before), while trying to match your needs (a nested menu to apply the suckerfish to it).
Offline
Re: category_list
Although I don’t know nothing about performance, this can probably go too resource-intensive, particularly if <txp:category_list break="" wraptag="ul">...</txp:category_list>
iterates over a long list of categories. You may want to reduce the amount of categories it will iterate by cleverly using the tag attributes that help to narrow down the list of categories, like type
, categories
, exclude
, parent
and children
.
Offline
Re: category_list
Julián – many thanks for that. I shall try it out on my current port which isn’t up on the demo site yet and see how it goes then if all is OK I’ll move the code over to “Aperture” et al and confirm here that it works or post any mods so other users can use it if need be.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#10 2010-10-08 03:30:17
- zeusdidit
- Member
- Registered: 2007-10-16
- Posts: 111
Re: category_list
Stuart,
Thanks for bringing this up since I needed a solution for exactly this.
Julian,
Thanks for that code snippet!! I was able to use much of it but had technical issues with section_list on the home page since no articles are set to section “default”, so no categories were showing up. So I wrapped the code into an if_section name=“default” so that I could show all categories on the home page, then I used part of your code to show categories per section. This is working for me rather magically at the moment and I’d like to send a huge thanks since it saved me a bit of time here and now I can stop using zillions of sections like I was before :)
You can check it out at blog.zeusdidit.com
Thanks gentlemen!
Zeus
<txp:if_section name="default">
<txp:category_list active_class="selected" label="Zeus' Categories" labeltag="h2" this_section="1" />
<txp:else/>
<txp:category_list break="" wraptag="ul" label="<txp:section/> Categories" labeltag="h2" this_section="1">
<txp:variable name="cat_has_articles_in_this_section"><txp:article_custom section='<txp:section />' category='<txp:category />' limit="1" sort="posted asc"><!-- (avoid querying/processing a form) --></txp:article_custom></txp:variable>
<txp:if_variable name="cat_has_articles_in_this_section" value="">
<txp:else />
<li><txp:category title="1" link="1" /></li>
</txp:if_variable>
</txp:category_list>
</txp:if_section>
Offline
#11 2010-10-09 01:46:12
- zeusdidit
- Member
- Registered: 2007-10-16
- Posts: 111
Re: category_list
And i have to retract because I just clicked and realized that my method does not work. Sorry…
Offline
Pages: 1