Textpattern CMS support forum

You are not logged in. Register | Login | Help

#271 2015-11-22 21:37:05

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

But a line listing of this shows that the value is drama.
<txp:variable name=“currentcategory” value=“drama” />
<txp:variable name=“currentcategory” />

Offline

#272 2015-11-22 21:43:04

etc
Developer
Registered: 2010-11-11
Posts: 3,359
Website

Re: etc_query: all things Textpattern

lazlo wrote #296761:

Nope it outputs all categories. But if I type replace ‘{?currentcategory}%’ with ‘drama’ it outputs just an A-Z list of drama books.

Very weird. Have you set globals="_GET" or something like that? Try with globals="variable", thought it should work by default.

Edit: and could it be that you use some pre 4.0.8 txp version?

Last edited by etc (2015-11-22 21:44:48)

Online

#273 2015-11-22 21:47:27

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

Very weird. Have you set globals="_GET" or something like that? Try with globals="variable", thought it should work by default.

I am embarrassed to say I have now idea where to do that. Which means I don’t think I have ever used such a setting unless some plugin has set those.

Last edited by lazlo (2015-11-22 21:47:52)

Offline

#274 2015-11-22 21:49:17

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

No using the latest version.
Textpattern version: 4.5.7 (r5900)
PHP version: 5.6.10

Offline

#275 2015-11-22 21:51:43

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

Testing on MAMP Pro install on OS X if that might mean anything?

Offline

#276 2015-11-22 21:54:42

etc
Developer
Registered: 2010-11-11
Posts: 3,359
Website

Re: etc_query: all things Textpattern

It’s like here

<!-- output alphalist and get articles ids when necessary -->
<txp:etc_query globals="_GET" data='<txp:variable name="alphalist" />'
...

Well, what is the output of just this:

<txp:variable name="currentcategory" value="drama" />
<txp:etc_query data='{?currentcategory}' />

Online

#277 2015-11-22 22:05:10

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

etc wrote #296767:

Well, what is the output of just this:

<txp:variable name="currentcategory" value="drama" />...

drama

Offline

#278 2015-11-22 22:22:36

etc
Developer
Registered: 2010-11-11
Posts: 3,359
Website

Re: etc_query: all things Textpattern

Fine, then

<txp:variable name="currentcategory" value="drama" />
<txp:etc_query markup="raw"
	data="SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 AND Section = 'books' AND Category2 LIKE '{?currentcategory}%' ORDER BY alpha" />

should output

SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 AND Section = 'books' AND Category2 LIKE 'drama%' ORDER BY alpha

If so, without markup="raw" attribute it should give a AC..X list, please check.

Online

#279 2015-11-22 22:26:55

etc
Developer
Registered: 2010-11-11
Posts: 3,359
Website

Re: etc_query: all things Textpattern

lazlo wrote #296766:

Testing on MAMP Pro install on OS X if that might mean anything?

This is fine, but I have noticed that some text editors on OS X tend to prettify the code way too much. Please check if straight quotes don’t become curly, and so on.

Online

#280 2015-11-23 19:40:12

lazlo
Member
Registered: 2004-02-24
Posts: 102

Re: etc_query: all things Textpattern

Hey Oleg

Thanks for being very patient. I just wanted to report back to you what I came up with in the end.

This is the code I eventually went with, it works as expected but parts had to be hard coded.

<!-- alpha list A-Z -->
<txp:variable name="currentcategory" value='<txp:category />' />

<txp:etc_query wraptag="ul" class="pull-right breadcrumb" break="li" name="alphalist"
	data="SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 AND Section = 'books' AND Category2 = '{?currentcategory}' ORDER BY alpha"
>
	<a href="<txp:site_url /><txp:section />/<txp:variable name="currentcategory" />/?alpha={alpha?}">{alpha?}</a>
</txp:etc_query>

<!-- output alphalist and get articles ids when necessary -->
<txp:etc_query globals="_GET" data='<txp:variable name="alphalist" />'
	query="//a[text() = '{?alpha|A}']"
	replace="&=<span class='active'>{?alpha|A}</span>"
>
	{//ul}
<txp:if_category name='drama'>
	<txp:etc_query name="ids" break="," globals="_GET"
		data="SELECT ID FROM textpattern WHERE UPPER(SUBSTRING(Title,1,1)) = '{?alpha|A}' AND Status = 4 AND Section = 'books' AND Category2 = 'drama' ORDER BY Title" />
</txp:if_category>

<txp:if_category name ='poetry'>
	<txp:etc_query name="ids" break="," globals="_GET"
		data="SELECT ID FROM textpattern WHERE UPPER(SUBSTRING(Title,1,1)) = '{?alpha|A}' AND Status = 4 AND Section = 'books' AND Category2 = 'poetry' ORDER BY Title" />
</txp:if_category>

<txp:if_category name ='fiction'>
	<txp:etc_query name="ids" break="," globals="_GET"
		data="SELECT ID FROM textpattern WHERE UPPER(SUBSTRING(Title,1,1)) = '{?alpha|A}' AND Status = 4 AND Section = 'books' AND Category2 = 'fiction' ORDER BY Title" />
</txp:if_category>

<txp:if_category name ='non-fiction'>
	<txp:etc_query name="ids" break="," globals="_GET"
		data="SELECT ID FROM textpattern WHERE UPPER(SUBSTRING(Title,1,1)) = '{?alpha|A}' AND Status = 4 AND Section = 'books' AND Category2 = 'non-fiction' ORDER BY Title" />
</txp:if_category>


<txp:else />
	<txp:variable name="alphalist" />
</txp:etc_query>

I (with your help) tried endlessly to get the right variable structure into the first part, only to have me find out that in the first etc_query this variable {?currentcategory} works but in the second etc_query it does not but this one does <txp:variable name=“currentcategory” /> (tested through raw output).

The following piece of code almost works, displays correct A-Z and correct category articles but when you click on the A-Z it just brings back the A articles regardless of which letter is clicked.

<!-- alpha list A-Z TEST-->
<txp:variable name="currentcategory" value='<txp:category />' />
TESTRED
<txp:variable name="currentcategory" />

<txp:etc_query wraptag="ul" class="pull-right breadcrumb" break="li" name="alphalist"
	data="SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 AND Section = 'books' AND Category2 = '{?currentcategory}' ORDER BY alpha"
>
	<a href="<txp:site_url /><txp:section />/<txp:variable name="currentcategory" />/?alpha={alpha?}">{alpha?}</a>
</txp:etc_query>

<!-- output alphalist and get articles ids when necessary -->
<txp:etc_query globals="_GET" data='<txp:variable name="alphalist" />' 
	query="//a[text() = '{?alpha|A}']"
	replace="&=<span class='active'>{?alpha|A}</span>"
>
	{//ul}
	<txp:etc_query markup="raw" name="ids" break="," globals="_GET"
		data="SELECT ID FROM textpattern WHERE UPPER(SUBSTRING(Title,1,1)) = '{?alpha|A}' AND Status = 4 AND Section = 'books' AND Category2 = '<txp:variable name="currentcategory" />' ORDER BY Title" />

<txp:else />
<txp:variable name="alphalist" />
</txp:etc_query>

Hardcoding ‘<txp:variable name=“currentcategory” />’ with “drama” in the second etc_query brings back expected results so that it what I did in my current working code. Again thanks for the patience, and the wonderful plug-in and code.

Last edited by lazlo (2015-11-23 19:42:52)

Offline

Board footer

Powered by FluxBB