Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-03-05 11:56:38

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

OR logic in custom_article

Hi,
I was wondering if it would make sense to add a new “logic= AND|OR” attribute to the “article_custom” tag.
I’ll try to explain it better: usually article_custom is called like this:

<txp:article_custom section="x" my_custom_field="y" />

This way the tag returns a list of articles which belong to section “x” AND have the custom field “my_custom_field” equal to “y”.
BUT
Sometimes I’d find very useful to have the possibility to list all articles which belong to section “x” or have the custom field “my_custom_field” equal to “y” calling the article_custom tag this way:

<txp:article_custom section="x" my_custom_field="y" logic="or" />

For a ‘real’ example suppose I want the home page to show a listing of updates to the site.
I want to include automatically all articles belonging to section “news” and – only when I want to – articles coming from another section.
So, in this scenario, when I want to include in the list an article not belonging to section “news” I could simply fill a certain custom field (or set a certain category).
I hope it makes some sense. Maybe there is already an easy way to do this but I wasn’t able to find it.

Offline

#2 2008-03-05 17:21:59

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: OR logic in custom_article

I think that would make the plugin code too complex, if we allow for all possible boolean combinations between various fields. Perhaps for the experienced users, we should offer an attribute “where”, that can contain part of the SQL query to restrict results. That’s more flexible, but also more error-prone, because users would have to be careful to supply a valid part of an SQL query.

Offline

#3 2008-03-06 01:13:21

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: OR logic in custom_article

Thanks for your answer ruud
though – probably due to my programming ignorance – I’m not sure I understood what you mean.
More specifically why you mention “all possible boolean combinations between various fields” ?
I thought I was referring only to two kind of boolean combinations between all fields
is there a great difference in terms of complexity between a query like this:
SELECT * FROM table WHERE a=b AND c=d AND e=f
and this:
SELECT * FROM table WHERE a=b OR c=d OR e=f?

Your “where” attribute idea seems interesting to me but, once again, I’m not sure I understood: I proposed an attribute to widen the results of the query, not to restrict it further.
Ok, for sure I misunderstood (OR I’m too ignorant to follow you;)) anyway thanks again for your answer

Offline

#4 2008-03-06 07:12:38

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: OR logic in custom_article

You’re asking for OR, some others will ask for a combination or AND + OR.
What I suggest is that the user can create the part of the SQL query that restricts the results all by himself and can supply it as an argument to the article tag. That way, people who know a bit of SQL can basically use any combination of AND / OR or whatever boolean operator they prefer.

Offline

#5 2008-03-06 10:28:21

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: OR logic in custom_article

Ok Ruud now I see, you were simply considerig a (lot) more advanced solution compared to the one I imagined.
Said that, your idea sounds great. Can I hope it will be some way implemented in the future?

Offline

#6 2008-03-07 15:49:13

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: OR logic in custom_article

Actually, I’ve thought before that we could benefit from a tag that could show the results of any SQL query. That would help in a lot of situations.

Offline

#7 2008-03-07 16:21:18

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: OR logic in custom_article

>redbot

There’s a few powerful conditional plugins that might help. (and yes I know that last one wasn’t technically a conditional.)

Last edited by mrdale (2008-03-07 16:22:28)

Offline

#8 2008-03-07 18:01:03

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: OR logic in custom_article

I was thinking more about making article(_custom) more flexible so all those plugins that essentially do the same thing only with a customized query could be replaced.

Offline

#9 2008-03-07 18:10:14

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: OR logic in custom_article

mrdale wrote:

There’s a few powerful conditional plugins that might help. (and yes I know that last one wasn’t technically a conditional.)

Thanks mrdale I know and have used some of them (and of course I couldn’t live without asy_wondertag) nonetheless the possibility
offered by an OR option or – even better – by an “any SQL query” option, as Mary sais, would help and simplify things in a lot of situations.
Anyway I must admit I never heard of ptv_if, it seems interesting…

ruud wrote

I was thinking more about making article(_custom) more flexible so all those plugins that essentially do the same thing only with a customized query could be replaced.

I was thinking the same

Last edited by redbot (2008-03-07 19:21:11)

Offline

#10 2008-06-04 15:58:57

alice_c
Plugin Author
From: Karlsruhe, Germany
Registered: 2004-07-03
Posts: 33

Re: OR logic in custom_article

Hi,

what is the status about there where-condition in article_custom? I really think this would help in lots of cases,
where I have a huge workaround…

Example: show only articles where custom_field greater than today (useful if you use articles for events..).

Offline

#11 2008-06-04 16:17:44

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: OR logic in custom_article

redbot wrote:

or – even better – by an “any SQL query” option, as Mary sais, would help and simplify things in a lot of situations.
Anyway I must admit I never heard of ptv_if, it seems interesting…

wish_granted

Remember to thank your favorite Brit.

Offline

#12 2008-06-04 23:48:51

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: OR logic in custom_article

alice-c,
this is what you’re looking for

mrdale wrote:

Remember to thank your favorite Brit.

Yep I remembered, look for the first comment after the plugin was released ;)

Last edited by redbot (2008-06-04 23:50:49)

Offline

Board footer

Powered by FluxBB