Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2007-05-04 14:13:17
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
if_category hates me
In an attempt at a clunky, manual solution to my “trying to display subcategory” thing I decided to try telling it to show articles in category Y if the current category was X. It no workie. Here is the snippet I tested:
<txp:if_category name="Creative-Writing">
<txp:recent_articles label="Poetry" limit="10" break="br" wraptag="p" category="Poetry" />
</txp:if_category>
In my test I’m only playing with the “Poetry” subcategory, but in the end I’m trying for something like this:
Creative Writing [this category has no direct content]
Poetry
(list here, titles only)
Stories
(list here, excerpt form)
Essays
(list here, excerpt form)
Currently the code being used in my site is this:
<txp:if_section name="tag">
<txp:tru_tags_handler form="tag_results" sortby="Posted" limit="10" />
<txp:else />
<txp:if_category>
<txp:article form="default" listform="excerpt" limit="5" pageby="10" />
<txp:output_form form="google468x60ad" />
<txp:article form="default" listform="excerpt" limit="5" offset="5" pageby="10" />
<txp:else />
<txp:article form="default" listform="excerpt" limit="1" />
</txp:if_category>
</txp:if_section>
So I’m not entirely sure what to add or where. I tried the snippet at the beginning of my post inserted right before the </txp:if_section> tag.
By the way, I have 6 categories that I want to display subcategories for… so if anyone knows a more automated way to do this, please let me know… like I said… clunky manual method here. If it matters, some of the top level categories have articles in them, but some don’t (like the one in this example… I will never be posting an article to “Creative Writing” itself, always to one of the subcategories).
Also by the way, I have reasons for using categories instead of sections for this, in case someone’s solution was gonna be that.
—
WebKat
Offline
#2 2007-05-04 14:43:26
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category hates me
If I understand you correctly, you could do something like this:
<txp:if_section name="tag">
<txp:tru_tags_handler form="tag_results" sortby="Posted" limit="10" />
<txp:else />
<txp:if_category name="creative-writing">
<h3>Poetry</h3>
<p>
<txp:article_custom limit="10" form="title-only" category="poetry" />
</p>
</txp:if_category>
<txp:if_category>
<txp:article form="default" listform="excerpt-not-cw" limit="5" pageby="10" />
<txp:output_form form="google468x60ad" />
<txp:article form="default" listform="excerpt-not-cw" limit="5" offset="5" pageby="10" />
<txp:else />
<txp:article form="default" listform="excerpt" limit="1" />
</txp:if_category>
</txp:if_section>
Form ‘title-only’:
<txp:permlink><txp:title /></txp:permlink><br />
Form ‘excerpt-not-cw’:
<txp:if_article_category name="creative-writing">
<!-- nothing here -->
<txp:else />
<!-- here the same code as in form 'excerpt', for category pages that are not 'creative writing' -->
</txp:if_article_category>
Oh, and don’t use capitals in category or section names, it can break things.
Offline
#3 2007-05-04 14:46:52
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category hates me
Reading back and forth between your two posts, I think my answer above is not complete yet. Please give me some time to think it over again.
EDIT: I’m sure I can think of something for your Creative Writing category page. But can you tell me if it’s always category 1, or always category 2, that you are using? It would make things easier.
Last edited by els (2007-05-04 14:50:03)
Offline
#4 2007-05-04 14:48:50
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
Re: if_category hates me
What can it break? It’s just that it’s kind of too late now, as the whole site has been up and running for quite some time and is already indexed by the search engines, and also many articles have hard-coded links to other parts of the site… I’d never track them all down and I’d end up breaking the site that way. If the stuff that can break from capitals is less likely than me breaking the site by having lots of broken links, I’ll go with it.
I’m off to try your suggestion now. Will report back soon! Thanks!
—
WebKat
Offline
#5 2007-05-04 14:49:39
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
Re: if_category hates me
Oh ok, I will wait then. turns on TiVo, begins watching yet another Stargate:SG-1
—
WebKat
Offline
#6 2007-05-04 14:51:59
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category hates me
I edited my post above, can you answer that question for me?
Offline
#7 2007-05-04 15:00:45
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
Re: if_category hates me
Yeah I’m looking at your suggestion and it seems like it’s only geared toward the creative-writing category… Here is the breakdown of my site’s categories:
Fun (8)- Movies (28)
- TV (1)
- Music (1)
- Games (8)
- Humor (9)
- Books
Kids (1)
Politics (1)
Rants (9)
Travel (5)
Health (3) - Food (8)
Web (3) - Geeky (4)
Art (3) - Clothing Design (4)
Events (2)
Creative Writing - Essays (1)
- Stories (3)
- Poetry (16)
Misc. (8)
Personal (16) - FencePosts (17)
I’m willing to hard code if_category stuff for each of the 6 categories that have subcategories, but I’d rather find a solution that is generic and will automatically do what I need… but anyway, whatever the solution is, it has to address that there will be, for example, the “Personal” page which should also link to (at minimum) or show content from the “FencePosts” subcategory, etc. The solution can’t be something that only works for the Creative Writing category and its subcategories.
On preview I see your new question: I use Category 1
Last edited by OpalCat (2007-05-04 15:01:18)
—
WebKat
Offline
#8 2007-05-04 15:27:38
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category hates me
Doing this with native textpattern tags would still involve a lot of hardcoding I think, something like this for every parent category:
<txp:if_category name="creative-writing">
<txp:article listform="excerpt" />
<txp:article_custom form="excerpt" category="essays" />
<txp:article_custom form="excerpt" category="stories" />
<txp:article_custom form="excerpt" category="poetry" />
</txp:if_category>
… and so on.
You might want to have a look at rss_suparchive, it might be of use for you, especially something like this example or the one just after it. It’s very customizable (is that a word?), you can use forms for the display of the article lists.
About the capitals in category or section names: maybe ‘break things’ is a big word, but I’ve seen it happen – several times – that some things just won’t work because of it (sorry, don’t have an example at hand right now). If you don’t want to change it, just keep this in mind when ‘things don’t work’ ;)
Last edited by els (2007-05-04 15:29:44)
Offline
#9 2007-05-04 15:41:25
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
Re: if_category hates me
Yes, that’s a word :)
I will go check out that plugin if that might make it easier. Thanks!
—
WebKat
Offline
#10 2007-05-04 16:09:09
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
Re: if_category hates me
It still hates me. I tried with the plugin and I tried your code above. I even tried making those categories lowercase temporarily to troubleshoot. Nothing happens. Here is the code I tried:
<txp:if_section name="tag">
<txp:tru_tags_handler form="tag_results" sortby="Posted" limit="10" />
<txp:else />
<txp:if_category name="creative-writing">
<txp:article listform="excerpt" />
<txp:article_custom form="excerpt" listform="excerpt" category="essays" />
<txp:article_custom form="excerpt" listform="excerpt" category="stories" />
<txp:article_custom form="poem_list" listform="poem_list" category="poetry" />
</txp:if_category>
<txp:if_category name="Web">
<txp:article listform="excerpt" />
<txp:article_custom form="excerpt" category="Geeky" />
</txp:if_category>
<txp:if_category>
<txp:article form="default" listform="excerpt" limit="5" pageby="10" />
<txp:output_form form="google468x60ad" />
<txp:article form="default" listform="excerpt" limit="5" offset="5" pageby="10" />
<txp:else />
<txp:article form="default" listform="excerpt" limit="1" />
</txp:if_category>
</txp:if_section>
When I go to the creative writing page, it’s got nothing but the google ad, same as always. cry
—
WebKat
Offline
#11 2007-05-04 16:16:22
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: if_category hates me
Besides changing to lowercase for the categories in the tag attributes, did you also change it in Content > Organize?
Edit: not that this causes the problem, but attribute ‘listform’ doesn’t exist for article_custom (as article_custom can only be used for article lists).
Last edited by els (2007-05-04 16:18:37)
Offline
#12 2007-05-04 16:21:24
- WebKat
- Member
- Registered: 2007-01-16
- Posts: 301
Re: if_category hates me
well yes, that is what I meant when I said I “tried making those categories lowercase temporarily”. Just changing it in the tag wouldn’t do anything except mean that it was pointing to categories that didn’t exist…?
—
WebKat
Offline