Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Differentiating if you are viewing a section or a category
Hi guys, I’ve hit a wall here, I am building a site that has the following structure:
- home (site.com)
-- section (site.com/section/)
--- category and section (site.com/section?c=category)
As you can see – I am using categories as subsections where a number of categories can belong to one section.
site.com/section/ should only show a static page – I have made it a sticky article, put it in the appropriate section, no categories assigned
site.com/section?c=category should show an intro article for that category followed by a list of articles from that same category. I made the intro article sticky, put it in the appropriate section and assigned it a category.
What I don’t understand is – I am obviously always in article list view – I never view individual articles and I think that is causing problems. I need code that will differentiate between the two stickies (the one that doesn’t have a category assigned should be displayed when site.com/section/ is viewed, and the one with the category assigned should be shown when site.com/section/?c=category is viewed).
So far I am using this but it’s obviously not working (from my pagetemplate):
<txp:if_category name="corporate-finance"><txp:article_custom status="sticky" category="corporate-finance" limit="1" />
<txp:article form="subArticle" limit="999" sort="Posted Asc" status="live" category="corporate-finance" /><txp:else /><txp:article_custom limit="1" status="sticky" id="14" /></txp:if_category>
As you can see I am in an act of desperation even tried to specifically assign categories from which the stickies should be pulled, but as soon as I need multiple categories per section this code doesn’t work like I want it to (it doubles [triples, quadruples…] the (not in category) sticky).
Last edited by draganbabic (2008-02-19 16:57:03)
Offline
Re: Differentiating if you are viewing a section or a category
OK, this code seems to do the trick, but I still don’t know how to show the section sticky for the site.com/section/ page.
<txp:if_category><txp:asy_wondertag><txp:article_custom status="sticky" category="<txp:category />" limit="1" /></txp:asy_wondertag>
<txp:asy_wondertag><txp:article form="subArticle" limit="999" sort="Posted Asc" status="live" category="<txp:category />" /></txp:asy_wondertag><txp:else />You are viewing a section</txp:if_category>
Offline
Re: Differentiating if you are viewing a section or a category
It could work be default if you ensured that the section article was created after the category article or modified the date to make it so. Then you could use <txp:article status="sticky" limit="1" />
after the “else” tag. Not perfect as it requires a bit of forward planning. ;)
Last edited by thebombsite (2008-02-19 17:55:12)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Differentiating if you are viewing a section or a category
Ahh, that is what I feared. :) It seems it will have to be like that.
PS
How the heck did we ever live without the asy_wondertag before? nowadays I can’t seem to do anything without it. :P
Offline
Re: Differentiating if you are viewing a section or a category
I have no idea Dragan. It’s one of those things that should be considered for the core code at some point along with Ruud’s CSS plug-in.
Anyway I should hang on in case someone has a bright idea about your problem. :)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Differentiating if you are viewing a section or a category
^ Definitely. But Ruud’s CSS plugin – I’m not aware of it, could you please provide me with a link so I can check it out?
Offline
Re: Differentiating if you are viewing a section or a category
Yep. Here it is.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Differentiating if you are viewing a section or a category
Wow, that’s good stuff, thanks!
Offline
#9 2008-02-19 20:36:06
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Differentiating if you are viewing a section or a category
Have you tried this?
<txp:if_category>
<txp:asy_wondertag><txp:article_custom status="sticky" category="<txp:category />" limit="1" /></txp:asy_wondertag>
<txp:article form="subArticle" limit="999" sort="Posted asc" status="live" />
<txp:else />
<txp:article status="sticky" />
</txp:if_category>
(You don’t need asy_wondertag for the first article tag.)
Offline
Re: Differentiating if you are viewing a section or a category
#Els Yeah – that’s what I ended up with. Thanks.
Offline
Re: Differentiating if you are viewing a section or a category
A strange behavior – when I put gbp_permanent_links plugin to work articles wont list (the live ones). I have had this problem with categories (they wouldn’t list) but this is the first time so far with artcles. My rewrite rule is /section/category/ (No /article/ at the end because I don’t have individual articles.) Any hints?
Offline
Re: Differentiating if you are viewing a section or a category
This is the code I ended up with – gbp_permanent_links work too:
<txp:if_category><txp:asy_wondertag><txp:article status="sticky" category="<txp:category />" limit="1" /></txp:asy_wondertag>
<txp:asy_wondertag><txp:article_custom form="subArticle" limit="999" sort="Posted Asc" status="live" category="<txp:category />" /></txp:asy_wondertag><txp:else /><txp:article status="sticky" limit="1" /></txp:if_category>
Offline