Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-08-15 09:30:38

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Article_custom with custom field

I’m trying to control which articles appear on my homepage with a 4-value custom field. (Using glz_custom_fields, which makes it easy to do this with a 4-way radial selection.) I started out with None/High/Medium/Low, and then did this on the homepage:

<txp:article_custom time="any" form="2014-homepage-featured" Featured="High" />
<txp:article_custom time="any" form="2014-homepage-featured" Featured="Medium" />
<txp:article_custom time="any" form="2014-homepage-featured" Featured="Low" />

… but now I’d like to set an overall limit, which means combining these into one article_custom that sorts by the custom field Featured. I changed the custom field to use 0/1/2/3, but the problem is that Featured="1, 2, 3" doesn’t produce any output. Any suggestions that don’t involve using separate custom fields for “on homepage, yes/no” and “homepage priority”?


Yes, I have tried turning it off and on.

Offline

#2 2014-08-15 09:45:53

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

Re: Article_custom with custom field

If you use 0/11/12/13 as Featured values, this should work:

<txp:article_custom time="any" form="2014-homepage-featured" Featured="1%" />

Edit: or [Empty]/Low/Medium/High and

<txp:article_custom time="any" form="2014-homepage-featured" Featured="_%" />

Last edited by etc (2014-08-15 09:58:22)


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

Offline

#3 2014-08-15 14:50:41

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Article_custom with custom field

Ahh, that’s fantastic.

But with the second option (which is much preferable otherwise) there’s no way to make it sort by that value, is there?


Yes, I have tried turning it off and on.

Offline

#4 2014-08-15 16:15:50

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,129
Website

Re: Article_custom with custom field

alesh wrote #282934:

… but now I’d like to set an overall limit, which means combining these into one article_custom that sorts by the custom field Featured.

What do you mean by “overall limit?” Are you thinking of having multiple high, medium, and low articles or something like that?

Offline

#5 2014-08-15 16:26:12

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

Re: Article_custom with custom field

alesh wrote #282941:

But with the second option (which is much preferable otherwise) there’s no way to make it sort by that value, is there?

There is (to test):

<txp:php>safe_query("SET @ord1='High', @ord2='Medium', @ord3='Low'");</txp:php>

<txp:article_custom ... sort="FIELD(custom_n, @ord1, @ord2, @ord3)" />

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

Offline

#6 2014-08-15 21:14:27

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Article_custom with custom field

michaelkpate wrote #282943:

What do you mean by “overall limit?” Are you thinking of having multiple high, medium, and low articles or something like that?

Yes, for sure.

etc wrote #282944:

There is (to test):

<txp:php>safe_query("SET @ord1='High', @ord2='Medium', @ord3='Low'");</txp:php>
<txp:article_custom ... sort="FIELD(custom_n, @ord1, @ord2, @ord3)" />

That works spectacularly! The eventual goal is to have some of these articles styled differently (think the homepage of Slate, but auto-generated). For starters:

<txp:php>safe_query("SET @ord1='High', @ord2='Medium', @ord3='Low'");</txp:php>
<txp:article_custom time="any" Featured="_%" form="2014-homepage-mega-featured" sort="FIELD(custom_12, @ord1, @ord2, @ord3), Posted desc" limit="1" />
<txp:article_custom time="any" Featured="_%" form="2014-homepage-featured" sort="FIELD(custom_12, @ord1, @ord2, @ord3), Posted desc" limit="10" offset="1" />

Thanks!!


Yes, I have tried turning it off and on.

Offline

#7 2016-10-20 16:47:12

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Article_custom with custom field

etc wrote #282935:

If you use 0/11/12/13 as Featured values, this should work:

<txp:article_custom time="any" form="2014-homepage-featured" Featured="1%" />...

Edit: or [Empty]/Low/Medium/High and

<txp:article_custom time="any" form="2014-homepage-featured" Featured="_%" />...

Ok, now I’m trying to squeeze some more flexibility out of this code … what are my options with Featured=""? I’d like to deal with Featured="High" Separately, but pretty sure I can’t do Featured="Medium,Low" … is there some other way to go?

Right now my best idea is to change the possible values in the custom field to something like “a. High” “b. Medium” “b. Low” and then use Featured="a%" and Featured="b%". The real downside is that if I figure out something else I want to do in the future I need to change the values in the custom field for all existing articles.


Yes, I have tried turning it off and on.

Offline

#8 2016-10-20 17:11:18

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 959
Website

Re: Article_custom with custom field

Alesh,

Bloke’s smd_featured does not do exactly the same thing as your set up and code above, but I don’t think it’s completely dissimilar. In case it helps give you some ideas/solutions.

Offline

#9 2016-10-20 17:16:38

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

Re: Article_custom with custom field

That’s quite easy: with Low=100, Medium=010, High=001 you can get any combination by setting to 0 the “bytes” of excluded values. So, for Low,Medium it will be

<txp:article_custom Featured="__0" ... />

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

Offline

#10 2016-10-21 13:26:00

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

Re: Article_custom with custom field

etc wrote #302361:

That’s quite easy: with Low=100, Medium=010, High=001 you can get any combination by setting to 0 the “bytes” of excluded values. So, for Low,Medium it will be

<txp:article_custom Featured="__0" ... />...

Ahh, Great! I ended up going with the values “000 None”, “001 Low”, “010 Medium”, and “100 High”. I figured I could get any combination of levels that way, but I’m running into a snag. Adding Featured="0%" to my article_custom should include everything except “100 High”, right? But it also seems to be leaving out “000 None”.

(I’m messing with one particular article. When I change it from “000 None” to “001 Low” it shows up, and when I remove Featured="0%" it shows up, but otherwise it disappears.)

Am I doing something obvious wrong?


Yes, I have tried turning it off and on.

Offline

Board footer

Powered by FluxBB