Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2012-05-28 22:54:42

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

Re: etc_query: all things Textpattern

Thanks for your help. I was able to switch to PHP 5.3.8 so the error is gone.

I admit to being quite lost at this point though, probably because I don’t understand xpath syntax well enough.

you will still have to display the articles of the current page using the pgc value in some way (offset?), which depends on your context.

It seems that is the meat of the problem—I’m not sure how to do that. I think I will try the method described in the TXP tip for now.

Offline

#26 2012-05-29 09:16:36

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_query: all things Textpattern

This is quite easy to do if your url contains only one variable (?id or ?pgc). Define a variable for navigation, say “pgc_list”:

<txp:variable name="pgc_list">
  <txp:etc_query
    data='<txp:article_custom limit="999"><a href="#">#</a></txp:article_custom>'
    query="a[position() mod 10 = 1]"
  >
    <a href="?pgc={#row}">{#row}</a>
  </txp:etc_query>
</txp:variable>

Then put something like this in the page form:

<txp:if_individual_article>
  <nav><txp:variable name="pgc_list" /></nav>
<txp:else />
  <txp:etc_query
    data='<txp:variable name="pgc_list" />'
    globals="_GET"
    query="a[{?pgc|1|intval}]"
    replace="@@class=current"
  >
    <!-- current page articles -->
    <txp:article_custom wraptag="div" offset="{?pgc|0|intval,-1,*10}" limit="10" />

    <!-- navigation links, with prev/next -->
    <nav>
    {preceding-sibling::a[1]=[Prev]}
    <txp:variable name="pgc_list" />
    {following-sibling::a[1]=[Next]}
    <a href="???">[View All]</a>
    </nav>
  </txp:etc_query>
</txp:if_individual_article>

Be sure to use v0.9 or above.

Last edited by etc (2012-05-30 21:28:18)

Offline

#27 2012-06-03 15:51:27

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_query: all things Textpattern

Now it is even easier to create the navigation list with etc_url:

<txp:variable name="pgc_list">
  <txp:etc_query
    data='<txp:article_custom limit="999"><a href="#">#</a></txp:article_custom>'
    query="a[position() mod 10 = 1]"
  >
    <a href='<txp:etc_url query="pgc={#row}" />'>{#row}</a>
  </txp:etc_query>
</txp:variable>

will preserve the url, just appending pgc=n to it.

Offline

#28 2012-07-03 12:51:20

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_query: all things Textpattern

Version 0.97 is out, certainly the last step towards 1.0. More robust parser, implying small syntax changes in function patterns ($[...]$ -> {$...}).

Offline

#29 2012-08-01 14:42:46

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: etc_query: all things Textpattern

The following line of … umpteen posts was transferred over here from the adi_gps_topic as it had only to do with etc_query. Its essence is a new topic in the How-tos-and-Examples forum, “Front End Search: Filter Articles With Drop-Down and Multi-Select Menu”. You might want to skip all of the dialogue between etc and progre55 and read on here in the etc_query topic.
Uli

ORIGINAL POST FROM ADI_GPS TOPIC:
–––––––––––––––––––––––––––––––––––––
Hope someone can assist.

I have used the following as a guide and it worked perfectly. I customized it to fit my project and the url displays the specific data and the search results displayed properly. My problem is that I have been unsuccesful in adding a third drop down into the mix (and in fact I will have many more). I tried numerous combinations with no success – see one example below.

I am trying to give the end user the option of selecting Color and getting results; selecting Model and getting results; selecting Price and getting results and/or any Combination.

Below is the unsuccesful code I am using:

<txp:adi_gps name="Color" quiet="1" />
<txp:adi_gps name="Model" quiet="1" />
<txp:adi_gps name="Price" quiet="1" />

<txp:if_variable name="Price" value="">
<txp:if_variable name="Color" value="">
<txp:if_variable name="Model" value="">

<txp:article />
<txp:else />
<txp:article_custom Model='<txp:variable name="Model" />' />
</txp:if_variable>
<txp:else />
<txp:if_variable name="Model" value="">
<txp:article_custom Color='<txp:variable name="Color" />' />
<txp:else />
<txp:article_custom Model='<txp:variable name="Model" />' Color='<txp:variable name="Color" />' />
</txp:if_variable>
<txp:if_variable name="Model" value="">
<txp:article_custom Price='<txp:variable name="Price" />' />
<txp:else />
<txp:article_custom Model='<txp:variable name="Model" />' Color='<txp:variable name="Color" />' Price='<txp:variable name="Price" />'/>
</txp:if_variable>
</txp:if_variable>
</txp:if_variable>

Any guidance would be greatly appreciated.

progre55

Last edited by uli (2012-08-07 19:34:03)

Offline

#30 2012-08-01 21:03:19

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_query: all things Textpattern

I don’t know why it does not work, sorry (maybe upper/lowercase problem?), but I wouldn’t do so much code replication anyway. Once you have assigned variables with adi_gps, something like this should work:

<txp:etc_query globals="variable" data="{?Color,Model,Price}">
  <txp:article_custom
    {$?({?Model}|Model='<txp:variable name="Model" />'|)}
    {$?({?Color}|Color='<txp:variable name="Color" />'|)}
    {$?({?Price}|Price='<txp:variable name="Price" />'|)}
  />
<txp:else />
  <txp:article />
</txp:etc_query>

Offline

#31 2012-08-01 21:21:54

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: etc_query: all things Textpattern

etc:

Thank you for your response and I am all for reducing code duplication. I tested the above code and the probem is if you just select Color or Just Select a Price or do a combination of a Color and Price nothing happens. If I Select a Model — it returns all the articles that have a Model in that field and does not distinguish between them. Also, selecting a Model and either Price or Color or Both resturns the same article list.

progre55

Offline

#32 2012-08-01 21:30:58

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_query: all things Textpattern

Weird. If you unwrap it from <txp:article_custom />

<txp:etc_query globals="variable" data="{?Color,Model,Price}">
    {$?({?Model}|Model='<txp:variable name="Model" />'|)}
    {$?({?Color}|Color='<txp:variable name="Color" />'|)}
    {$?({?Price}|Price='<txp:variable name="Price" />'|)}
<txp:else />
  <txp:article />
</txp:etc_query>

what do you get?

Offline

#33 2012-08-01 21:37:41

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: etc_query: all things Textpattern

etc.

I apologize but your original code actually did the trick. When I altered one of the variables (changed Price to Year) because I had changed it in the site, I missed a place in the code you provided which was jacking everything up. Now, the search form returns all of the expected results. THANK YOU.

With the reduction in replication, this will also make it much easier for me to add additional fields.

progre55

Offline

#34 2012-08-01 21:41:21

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: etc_query: all things Textpattern

etc:

I just noticed — the original code works if I do just Model. Model and Color. Model Color and Price. But if I do not select a Model — just using the Color and Price does not return any results.

progre55

Last edited by progre55 (2012-08-01 21:41:37)

Offline

#35 2012-08-01 21:41:44

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: etc_query: all things Textpattern

Fine then, glad it helps!

Offline

#36 2012-08-01 21:43:32

progre55
Member
Registered: 2006-05-02
Posts: 668

Re: etc_query: all things Textpattern

etc.

I spoke a little to soon. Let me know your thoughts on what may be causing the results as mentioned in my last response.

progre55

Offline

Board footer

Powered by FluxBB