Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Use an article form to display a list of categories
I want to display a list of all the categories in a section using a custom form (this will appear on the front page of the different sections). Unfortunately, the form attribute isn’t part of the <txp:category_list /> tag nor any other category related plugin. My output should look somthing like this: 5 articles in Music (where ‘5’ is the number of articles in the category, ‘music’ the category name):
<a href="/linktocategorypage"><txp:mem_article_count /> articles in <txp:category /></a>
I thought that the <txp:article_custom /> and <txp:if_different> tags could resolve this:
<article_custom form="categorylist" section="blabla" sortby="Category" />
+ categorylist form:
<txp:if_different>
<txp:category>
<txp:asy_wondertag><txp:mem_article_count category="<txp:category1 title="1" />" /></txp:asy_wondertag>
articles in <txp:category title="1" />
</txp:category>
</txp:if_different>
but it seems that the <txp:category /> tag doesn’t want to play along (nor does sortby=“Category”), it returns nothing when called in the article form. (This technique does work with Category1 or Category2: this post similarly answers that. The only problem with this is it obviously does not display all possible categories.) Plus <txp:mem_article_count /> returns the number of articles in the section, not by category.
Any hints? Have I missed something obvious anywhere?
Maybe something between two <txp:php> tags? A new plugin? An attribute for an existing one (asy_categories maybe)?
Thanks in advance
Offline
Re: Use an article form to display a list of categories
See stw_category_tree – it can do that.
The sortby
value is deprecated and it have been changed to sort
that can be assigned with multiple sort criterias etc. sort="Category1 ASC"
and sort="Category1 ASC, Title DESC"
. Secondly, you can’t sort articles with category
as there isn’t that kind of field in textpattern table, only Category1 and Category2.
Cheers!
Last edited by Gocom (2008-01-06 23:35:51)
Offline
Re: Use an article form to display a list of categories
The <txp:category />
tag is more to do with “the category we are in”.
Last edited by thebombsite (2008-01-07 00:14:48)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Use an article form to display a list of categories
And there is also mistake in:
<txp:asy_wondertag><txp:mem_article_count category="<txp:category1 title="1" />" /></txp:asy_wondertag>
Use category’s name
, not the title. Also mem_article_count doesn’t even have that attribute – so why even bothering to use it. Also the txp:different
contains two TXP tags. So, there would be two changing values, and therefor the content would change when category or the count changes – causing dublicate categories.
And <txp:category />
only shows the category where we are in, based on the url, not the content nor article, as Stuart pointed out.
Cheers!
Last edited by Gocom (2008-01-07 00:26:42)
Offline
Re: Use an article form to display a list of categories
Jukka: Thanks, but this plugin outputs a list, not single elements that can be placed in a form… Do I have to hack it? (I’m php-stupid btw)
And yeah, the sort thing, silly me, thanks.
Stuart: thanks for clarifying. Makes sense why it doesn’t work that way. Wish there was a either-or-cat tag.
Offline
Re: Use an article form to display a list of categories
right now it’s working well for only Cat1 alone like this:
<txp:if_different>
<li><txp:category1>
<txp:asy_wondertag><txp:mem_article_count category="<txp:category1 title="1" />" section="links" /></txp:asy_wondertag>
<span class="linkinfo">articles in</span>
<txp:category1 title="1" />
</txp:category1></li>
</txp:if_different>
Is it even possible to add the Cat2 in there?
Or am I totally going in the wrong direction with this?
Last edited by edemay (2008-01-07 00:33:46)
Offline
Re: Use an article form to display a list of categories
Thanks, but this plugin outputs a list, not single elements that can be placed in a form… Do I have to hack it? (I’m php-stupid btw)
stw_category_tree has following label
, labeltag
, wraptag
, break
so you could produce you example. I don’t know what you mean by form, as the plugin can be used at any context.
Cheers!
Last edited by Gocom (2008-01-07 00:34:08)
Offline
Offline
Re: Use an article form to display a list of categories
Wow! thanks Jukka. Unfortunately, it doesn’t seem to work. :S It returns a bunch of:
Tag error: <txp:php> -> Warning: Missing argument 1 for category2() on line 1896
Tag error: <txp:php> -> Warning: array_keys() [
function.array-keys
]: The first argument should be an array on line 604
Tag error: <txp:php> -> Warning: array_diff() [
function.array-diff
]: Argument #1 is not an array on line 604
Tag error: <txp:php> -> Warning: Invalid argument supplied for foreach() on line 604
Tag error: <txp:php> -> Warning: Missing argument 1 for category1() on line 1846
Tag error: <txp:php> -> Warning: array_keys() [
And where do I insert the rest of the code that I stated earlier (with the working Cat1)? I’m guessing after the if_different tags right?
Btw, I really appreciate you taking the time to help me solve this. Thank you.
Offline
Re: Use an article form to display a list of categories
btw, I solved this by hacking the cbs_category_list plugin’s output. thanks anyways.
Offline