Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#241 2015-09-12 09:33:41

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

Re: etc_query: all things Textpattern

Nothing to be sorry about, that helped me to fix few glitches.

Offline

#242 2015-09-12 09:46:27

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

Re: etc_query: all things Textpattern

Version 1.3.1 is out, just few minor fixes and 4.6 compatibility.

Offline

#243 2015-09-12 12:41:35

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: etc_query: all things Textpattern

etc wrote #294749:

Version 1.3.1 is out, just few minor fixes and 4.6 compatibility.

Thanks!

Any advice about the use of regex to allow me to create excerpt from the boby tag properly? My code is:

<txp:etc_query data='<txp:body />' specials="" query="substring(//p[1], 0, 140)" limit="1" wraptag="p" />

…but, of course, it does not cut properly. Cutting after the last entire word before the character 140 would be better.

Edit: it’s maybe even possible to add &hellip;?

Last edited by NicolasGraph (2015-09-12 12:43:26)


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#244 2015-09-12 16:50:43

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

Re: etc_query: all things Textpattern

You can register any php (string) function for use with etc_query. I’m not sure this is optimal, but it should work:

<txp:etc_query data='<txp:body />' specials="" functions="preg_replace,trim" limit="1" wraptag="p"
    query="preg_replace('/\w*:::/', '&hellip;', preg_replace('/^(.{140}).+/s', '$1:::', trim(string(p[1]))))" />

Edit: but be careful if you use it inside another etc_query, you might need to protect the {140} part.

Last edited by etc (2015-09-12 21:20:19)

Offline

#245 2015-09-12 17:04:58

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: etc_query: all things Textpattern

etc wrote #294752:

You can register any php (string) function for use with etc_query. I’m not sure this is optimal, but it should work.

Thank you Oleg…


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#246 2015-09-23 14:01:35

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: etc_query: all things Textpattern

Hi,
I would like to know if there is any chance to make the following code work…
I’m looking for three comma separated image id’s in the article_image field but I can’t make REGEXP work.
Is that possible? Do I need to use the functions attribute? …

<txp:etc_query data="Image REGEXP '^((\d+,)\s*){2}\d+$'" populate="article">
	<txp:article_image />
</txp:etc_query>

Thanks…


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#247 2015-09-23 17:40:41

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

Re: etc_query: all things Textpattern

No, but since you are in db mode here, you must use MySQL regexp notations, which are weird. Try (no warranty)

<txp:etc_query markup="db" populate="article"
	data="Image REGEXP '^(([[:digit:]]+,)[[:space:]]*){2}[[:digit:]]+$'"
>
	<txp:article_image />
</txp:etc_query>

Offline

#248 2015-09-24 20:58:44

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: etc_query: all things Textpattern

etc wrote #295096:

No, but since you are in db mode here, you must use MySQL regexp notations, which are weird. Try (no warranty)

<txp:etc_query markup="db" populate="article"...

Thanks, I’ll give it a try and learn more about MySQL regexp notations after holydays.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#249 2015-10-17 14:22:36

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: etc_query: all things Textpattern

NicolasGraph wrote #295093:

Hi,
I would like to know if there is any chance to make the following code work…
I’m looking for three comma separated image id’s in the article_image field but I can’t make REGEXP work.
Is that possible? Do I need to use the functions attribute? …

<txp:etc_query data="Image REGEXP '^((\d+,)\s*){2}\d+$'" populate="article">...

Thanks…

I can’t get it work but it is not really important. Thank you for your reply.


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#250 2015-10-17 15:46:21

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

Re: etc_query: all things Textpattern

That works for me, but may be server-dependent.

Offline

#251 2015-11-05 22:16:21

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

Re: etc_query: all things Textpattern

Hi Oleg (SOLVED)

I am implementing your wonderful A-Z filter / paginated A-Z article list but I am having trouble limiting the database call to specific textpattern section.

Is there a way to adjust this call to delimit textpattern sections?
I have a section called “Books” to be specific.

<txp:etc_query wraptag="nav" break=" | " name="alphalist"
	data="SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 ORDER BY alpha"
>
	<a href="?alpha={alpha?}">{alpha?}</a>
</txp:etc_query>

I have tried various iterations on the call by adding AND Section = ‘books’ but with no success.

I didn’t realize there were two calls that needed to be changed so the following is the solution.

NEW Code



<!-- alpha list -->
<txp:etc_query wraptag="nav" break=" | " name="alphalist"
	data="SELECT DISTINCT UPPER(SUBSTRING(Title,1,1)) AS alpha FROM textpattern WHERE Status = 4 AND Section = 'books' ORDER BY alpha"
>
	<a href="?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>"
>
	{//nav}
	<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' ORDER BY Title" />
<txp:else />
	<txp:variable name="alphalist" />
</txp:etc_query>

<txp:if_variable name="ids">
	<!-- Pagination bar -->
	<txp:etc_query name="pages" data="{?ids|1|substr_count($|,).+1./2.ceil}" />
	<txp:etc_pagination pgcounter="page" link="Page {*}" wraptag="nav" break=" | "
		pages='<txp:variable name="pages" />'  />
	<!-- articles output -->
	<txp:article_custom id='<txp:variable name="ids" />' limit="2"
		offset='<txp:etc_offset pgcounter="page" pageby="2" />' />
</txp:if_variable>

Last edited by lazlo (2015-11-05 23:16:55)

Offline

#252 2015-11-06 09:43:19

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

Re: etc_query: all things Textpattern

Hi Leslie, glad you have solved it. For multiple sections, you can add

Section IN('books', 'news')

to the appropriate WHERE clauses. And if you have expired/future articles, you may need also

 (NOW() <= Expires OR Expires = '0000-00-00') AND Posted <= NOW()

Last edited by etc (2015-11-06 10:41:07)

Offline

Board footer

Powered by FluxBB