Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2018-11-10 14:22:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

etc wrote #315154:

I think this could work.

Ah sorry, didn’t spot that post. Yes, that works perfectly well, thank you. And doesn’t seem that resource hungry either. I added a little defensive if_variable goodness around the second category_list in case there’s no stock at any given location. Thank you so much, Oleg. Saved my sanity!

Independently, it would be easy to replace OR with AND when needed, we just need a syntax

I like that idea. As you say, the trick is coming up with a suitable syntax. A ‘plus’ for ‘OR’ might be a little counter intuitive as it might imply ‘add’ or ‘both’ to most.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2018-11-10 16:47:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

As a little further addendum I’d like to display how many articles are in the stock section that are not SOLD and show it in the article title of the stocklist.

Presumably with some judicial use of escape magic in 4.7, I can add <txp:php> safe_count(...);</txp:php> in the article title, but so far it’s resisting my advances. Any clues how I can get this value out and displayed on the page where the <txp:title/> tag is?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#13 2018-11-10 16:54:11

etc
Developer
Registered: 2010-11-11
Posts: 2,947
Website

Re: article_custom from both categories (AND)

Bloke wrote #315155:

the trick is coming up with a suitable syntax.

As always. If I understand your OP requirement, we need

Category1='location' AND Category2='type'

A right syntax here could be

match="(Category1, Category2)" category="(location, type)"

but what to do then with

match="(Category1, Category2)" category="(location, type, something), else"

etc_[ query | search | pagination | date | tree | cache ]

Offline

#14 2018-11-10 16:59:02

etc
Developer
Registered: 2010-11-11
Posts: 2,947
Website

Re: article_custom from both categories (AND)

Bloke wrote #315156:

As a little further addendum I’d like to display how many articles are in the stock section that are not SOLD and show it in the article title of the stocklist.

Not sure to understand where you want it, but pgonly should work:

<txp:article_custom pgonly pageby="1" limit="999" price="SOLD" exclude="price" ... />

etc_[ query | search | pagination | date | tree | cache ]

Offline

#15 2018-11-10 17:39:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

Sorry I wasn’t clear. I want it to display the article count in the article title itself. Can we parse PHP code or tags in the article title field?

EDIT: I guess not, since dynamically changing the title might cause problems. I can always do it in the excerpt instead I suppose – I’ll just need a(nother) exception in my page-handling template.

Last edited by Bloke (2018-11-10 17:41:15)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#16 2018-11-10 18:20:58

etc
Developer
Registered: 2010-11-11
Posts: 2,947
Website

Re: article_custom from both categories (AND)

You mean a title like Welcome to <txp:site_name />!? This will be parsed when output by <txp:title escape="" />, but only on the second pass. And the context on the second pass can be different.

Edit: this said, nothing stops us from adding parse to possible escape values, but I’m not sure <txp:php /> should be eligible for parsing.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#17 2018-11-11 08:44:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

etc wrote #315160:

nothing stops us from adding parse to possible escape values, but I’m not sure <txp:php /> should be eligible for parsing.

Agreed. It’s fine as it is. I went with using the excerpt in the end and used another article custom call. Seems to work well.

I absolutely love working with the new tags in 4.7. So much scope for more natural and flexible tag structures. Thank you for all your help.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#18 2018-11-12 16:30:29

etc
Developer
Registered: 2010-11-11
Posts: 2,947
Website

Re: article_custom from both categories (AND)

Bloke wrote #315143:

I tried to do it in one giant article_custom call sorted by category2,category1 and then use if_different to show the headings but things fall apart when constructing the end table/tbody in the loop.

This difficulty has inspired test attribute of <txp:if_different />. In 4.7.2 the following should work (can be simplified if the counts are not needed):

<txp:variable name="thead">
  <thead>
    <tr>
      <th>Serial number</th>
      <th>Year</th>
      <th>Condition</th>
      <th>Price</th>
    </tr>
  </thead>
</txp:variable>

<txp:article_custom sort="Category1, Category2" limit="999">
  <txp:if_different test='<txp:category1 />.<txp:category2 />'>
    <txp:if_first_article not>
      <h3><txp:variable name="cat2" /> [<txp:variable name="count" />]</h3>
      <table><txp:variable name="thead" /><txp:variable name="table" wraptag="tbody" /></table>
    </txp:if_first_article>
    <txp:if_different><h2><txp:category1 title default="Untitled" /></h2></txp:if_different>
    <txp:variable name="cat2" value='<txp:category2 title default="Untitled" />' />
    <txp:variable name="count" value="0" />
    <txp:variable name="table" value="" />
  </txp:if_different>

  <txp:variable name="count" add />
  <txp:variable name="table">
    <txp:variable name="table" />
    <tr>
      <td><txp:custom_field name="Serial number" /></td>
      <td><txp:custom_field name="Year" /></td>
      <td><txp:custom_field name="Condition" /></td>
      <td><txp:custom_field name="Price" /></td>
    </tr>
  </txp:variable>

  <txp:if_last_article>
    <h3><txp:variable name="cat2" /> [<txp:variable name="count" />]</h3>
    <table><txp:variable name="thead" /><txp:variable name="table" wraptag="tbody" /></table>
  </txp:if_last_article>
</txp:article_custom>

etc_[ query | search | pagination | date | tree | cache ]

Offline

#19 2018-11-13 00:00:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: article_custom from both categories (AND)

etc wrote #315176:

This difficulty has inspired test attribute of <txp:if_different />.

Now that’s cool! I always tie myself up in knots trying to do that kind of thing because you need to handle the ‘end previous table, start next table’ case first… but only if not the first time, and then handle the closing table as a special case at the end. This approach wraps it up fairly neatly without needing all the extra variable baggage. Hats off to you, Sir.

I expect this will also help with making nested <ul> / <li> constructs, which is another tricky puzzle to do neatly in a loop.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#20 2018-11-13 11:02:17

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,156
Website

Re: article_custom from both categories (AND)

While I’m not sure I fully understood that last example (the counts have got me) it would be great to have solutions for the two things you mentioned in this thread. They’ve been common problems in the past, and some have required other plugins up to now:

  • Matching against combinations of categories (also custom_fields?!)
  • Handling if_first_article and if_last_article so that they don’t affect if_different when creating lists interspersed with headings.
    For the latter I’ve tried complex tricks with variables, hiding empty tags at the beginning with the :empty CSS selector or even wrapping the whole thing in a rah_replace or similar to search and replace out leftover empty tags in the output.

I’d love to see these new/extra attributes make those problems a thing of the past.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB