Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Show a section title only once in an article_custom list of sections?
I want to create a list of sections that have at least one article with, for example, a custom field called “size” set to some value.
First I tried:
<txp:article_custom section='<txp:variable name="section-list" />' size='<txp:variable name="size" />'>
<txp:if_different><txp:section title="1" /></txp:if_different>
</txp:article_custom>
However, this will display a section multiple times. For example:
Blue Cars Green Cars Orange Cars Blue Cars Orange Cars Green Cars
But what I would like is:
Bue Cars Green Cars Orange Cars
I’m not sure why it does it that first way (repeating the section names)…and I don’t want to repeat the titles. Any tips? Thanks!
Last edited by maruchan (2012-06-08 23:15:20)
Offline
Re: Show a section title only once in an article_custom list of sections?
Does sort="section"
help?
You’re telling it to print the section for each article that meets your criteria and the if_different
only compares it to the previous value.
Last edited by MattD (2012-06-08 23:30:42)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Show a section title only once in an article_custom list of sections?
Ah, OK, maybe I’m using the wrong approach then. What I need is this:
Foreach section in (list of sections)
Has this section name been displayed yet?
No: Does this section have any articles with the custom field "size" set to "large?"
No: Do nothing
Yes: Print section title
Yes: Do nothing
Last edited by maruchan (2012-06-09 02:40:31)
Offline
Re: Show a section title only once in an article_custom list of sections?
So, I guess I can just use smd_query. Example:
<txp:smd_query query="SELECT DISTINCT Section FROM txp1textpattern WHERE status=5" break="br">
<txp:section name="{Section}" title="1" />
</txp:smd_query>
Offline
Re: Show a section title only once in an article_custom list of sections?
Unless I’ve misunderstood something, I would have thought using sort="section asc, posted desc"
as MattD suggested should do the same. It retrieves only articles of matching size in a set of sections, then outputs the section titles in order.
Your pseudo code is possible with something like this but you might want to check whether that results in more db queries:
<txp:section_list sections='<txp:variable name="section-list" />'>
<txp:article_custom size='<txp:variable name="size" />' limit="999">
<txp:if_first_article><txp:section title="1" /></txp:if_first_article>
</txp:article_custom>
</txp:section_list>
Aside from that
TXP Builders – finely-crafted code, design and txp
Offline
Re: Show a section title only once in an article_custom list of sections?
maruchan a écrit:
I want to create a list of sections that have at least one article with, for example, a custom field called “size” set to some value.
MattD’s suggestion seems to be the good direction – just write it Section
(uppercase), and if you want to list all articles instead of the last 10th :
<txp:article_custom sort="Section" limit="9999" section='<txp:variable name="section-list" />' size='<txp:variable name="size" />'>
<txp:if_different><txp:section title="1" /></txp:if_different>
</txp:article_custom>
Last edited by CeBe (2012-06-09 09:20:40)
Offline
Re: Show a section title only once in an article_custom list of sections?
OK, went back and tried that (thinking, “why would sorting by section change anything?”) and it worked. :-) Thanks, Matt and everyone else.
Offline