Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2014-03-10 13:02:13
- txpdevcoder
- Member
- Registered: 2012-06-07
- Posts: 58
Complex Article list - HELP!
Hi,
I’m having some trouble listing some articles out, I’m hoping someone can help out.
I have three levels of categories, with an overview page at each level.
Section
|
-- Article Root Category
|
|
--- Sub Root Category - Overview
|
--- Sub One Category - Overview
-- Article One
-- Article Two
-- Article Three
|
|
--- Sub Root Category - Overview
|
--- Sub One Category - Overview
-- Article One
-- Article Two
-- Article Three
|
|
--- Sub Root Category - Overview
|
--- Sub One Category - Overview
-- Article One
-- Article Two
-- Article Three
I hope i can explain this. There are overview pages at the first level (Sub Root Category – Overview). When your viewing these top level overviews, these should only show links to the overview pages below it. When you are at the second level overview pages, this page should only list out articles that full under “Sub One Category” but not the overview page at this level.
The overview pages are assigned a category of “overview”.
Hopefully I have explained well enough for someone to help.
Last edited by txpdevcoder (2014-03-10 13:02:42)
Offline
Re: Complex Article list - HELP!
the code below would start you off but it is missing the overviews
<ul id="menu">
<li><a href="<txp:site_url />"><txp:site_name /></a></li>
<txp:category_list children="0" break="li">
<txp:category title="1" link="1" section='<txp:section />' />
<txp:article_custom category='<txp:category />' break="li" wraptag="ul" limit="999">
<txp:permlink><txp:title /></txp:permlink>
</txp:article_custom>
<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="" wraptag="ul">
<li><txp:category title="1" link="1" section='<txp:section />' />
<txp:article_custom category='<txp:category />' wraptag="ul" limit="999">
<li><txp:permlink><txp:title /></txp:permlink></li>
</txp:article_custom></li>
</txp:category_list>
</txp:category_list>
</ul>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2014-03-10 15:39:03
- txpdevcoder
- Member
- Registered: 2012-06-07
- Posts: 58
Re: Complex Article list - HELP!
Thanks Colak, but its not quite what i need. It’s hard to explain.
Im not trying to display the whole tree above. When you view an overview page, you need to see just the overview pages at the second level below that.
So if you were viewing the top level overview page would see just this:
Sub Root Category - Overview Article (this is the page im viewing in the browser, the below are article links)
|
--- Sub One Category - Overview
|
--- Sub One Category - Overview
|
--- Sub One Category - Overview
|
--- Sub One Category - Overview
Then when you click a link to a “Sub One Category – Overview” you just see:
--- Sub One Category - Overview (this page gets omitted from the links because its the page i'm currently looking at in the browser)
-- Article One
-- Article Two
-- Article Three
You see? Basically as you move down through the parent categories, you only see the child category overviews below that and then at the second level you see the articles listed out.
Is this possible?
Last edited by txpdevcoder (2014-03-10 15:45:11)
Offline
Re: Complex Article list - HELP!
I see… This seems simpler. Here’s an untested suggestion which needs further development.
<txp:if_category name='<txp:category />'>
<txp:variable name="childrencategory" value='<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="" wraptag="" />' />
<txp:hide>I am not sure how the particular article will be parsed here but an option would be for the article to have a custom field the same value as the name of the category</txp:hide>
<txp:article_custom category="overview" custom_field1='<txp:category />'><txp:body />
</txp:article_custom>
<txp:if_variable name="childrencategory" value=""> <txp:hide>the category has no children</txp:hide>
<txp:article break="li" wraptag="ul"><txp:permlink><txp:title /></txp:permlink></txp:article>
<txp:else />
<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="li" wraptag="ul" />
</txp:if_variable>
</txp:if_category>
>Edited to add some code which hopefully comes closer to what you need
Last edited by colak (2014-03-10 18:59:11)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Complex Article list - HELP!
Not sure if I understood this all, but instead of using an “overview” category to denote the overview articles, could you not give the overview articles “sticky” status?
For the first level overview, you could use txp:category_list to output a comma-separated list of child categories into a variable, something like this:
<txp:variable name="sub-categories"><txp:category_list parent='<txp:category />' exclude='<txp:category />' break="," wraptag="" /></txp:variable>
Then you can pull out all the sticky articles in the child categories using txp:article_custom
along with the attribute status="sticky"
e.g. something like this:
<txp:article_custom status="sticky" section="my-section" category='<txp:variable name="sub-categories" />'>
<div>
<h1><txp:title /></h1>
<txp:excerpt />
<!-- instead of permlink, generate a link to the category specified in category1 of your sticky article -->
<a href="<txp:site_url /><txp:section>?c=<txp:category1 />">Link to sub-category</a>
</div>
</txp:article_custom>
For the second level sub-category view, you can use normal txp:article(_custom) functions to generate a list of articles in that category. By default it only shows “live” articles, so the sticky overview article won’t show.
<txp:article_custom section="my-section" category='<txp:category />'>
<article>
<h1><txp:title /></h1>
<txp:excerpt />
<a href="<txp:permlink />">Read more</a>
</article>
</txp:article_custom>
Now all you need is to determine whether the page you are on is a first or second level category. Either you generate a list of the first-level categories (i.e. txp:category_list
with parent="article root category" children="1"
) at the top of your page and put it in a variable so that you can compare against it with something like smd_if or if your site won’t vary much, you simply manually code your top-level categories. Sometimes I save this manual list in a site-wide variable using adi_variable so that should the need ever arise, it can be extended later.
TXP Builders – finely-crafted code, design and txp
Offline
#6 2014-03-11 10:01:40
- txpdevcoder
- Member
- Registered: 2012-06-07
- Posts: 58
Re: Complex Article list - HELP!
Thanks Jakob. I will try your suggestion however ideally I would like to keep category URLs out of it. THe categories are used to organise the articles, but i would rather keep to clean URLs if i can.
The overview pages are pages of text with a list of links at the top. They are not technically a category page.
I’ll see how it goes…. Thanks :)
Offline
Re: Complex Article list - HELP!
jakob had a good idea there so here’s the code which should work I think
<txp:if_category name='<txp:category />'>
<txp:variable name="childrencategory" value='<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="" wraptag="" />' />
<txp:article_custom category='<txp:category />' status="sticky">
<txp:body />
</txp:article_custom>
<txp:if_variable name="childrencategory" value=""> <txp:hide>the category has no children</txp:hide>
<txp:article break="li" wraptag="ul"><txp:permlink><txp:title /></txp:permlink></txp:article>
<txp:else />
<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="li" wraptag="ul" />
</txp:if_variable>
</txp:if_category>
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#8 2014-03-11 12:06:23
- txpdevcoder
- Member
- Registered: 2012-06-07
- Posts: 58
Re: Complex Article list - HELP!
Ahhh thanks Colak, its almost what i need. I don’t want to use category list after the else.
You are on the right lines though. Instead of category list, i need a list of articles that belong to the category that has no child categories.
<txp:if_category name='<txp:category />'>
<txp:variable name="childrencategory" value='<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="" wraptag="" />' />
<txp:article_custom category='<txp:category />' status="sticky">
<txp:body />
</txp:article_custom>
<txp:if_variable name="childrencategory" value=""> <txp:hide>the category has no children</txp:hide>
<txp:article break="li" wraptag="ul"><txp:permlink><txp:title /></txp:permlink></txp:article>
<txp:else />
<!-- list articles here that belong to category that has no children -->
</txp:if_variable>
</txp:if_category>
is there anyway to know what the category that has no children is? I will need to know that to use article custom to list out permlinks.
Offline
#9 2014-03-11 12:09:50
- txpdevcoder
- Member
- Registered: 2012-06-07
- Posts: 58
Re: Complex Article list - HELP!
Just to be clear, i am not using categories on the front end. I am purely using the categories to organise things on the back end.
This site is a business site, not a blog so every page is either a sticky article or a live article.
I am not displaying anything using category pages or generating category style links. I am just using categories to filter article_custom tags to generate permlinks to the right pages depending on the page you are looking at.
Last edited by txpdevcoder (2014-03-11 12:13:17)
Offline
Re: Complex Article list - HELP!
I see what you need now. I’m trying to think how the parent category could be detected which I’m not sure if it can using native tags (please somebody prove me wrong). It then needs to serve a list of its articles which it should be straight forward using article_custom
and a parent category variable maybe.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#11 2014-03-11 14:00:17
- txpdevcoder
- Member
- Registered: 2012-06-07
- Posts: 58
Re: Complex Article list - HELP!
I don’t mind using plugins :)
PLease, if you have any thoughts… this has been driving me nuts for days!
Offline
Offline