Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-06-08 23:14:53

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 564
Website

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

#2 2012-06-08 23:29:51

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,196
Website

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)


My Plugins

Piwik Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#3 2012-06-09 00:43:56

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 564
Website

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

#4 2012-06-09 03:26:18

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 564
Website

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

#5 2012-06-09 07:02:55

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 1,960
Website

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

#6 2012-06-09 09:20:00

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 289
Website

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

#7 2012-06-10 03:55:10

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 564
Website

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

Board footer

Powered by FluxBB