Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#166 2008-11-19 09:55:09
Re: smd_if: Generic multiple if condition tests
roelof wrote:
this plugin is not working properly with 4.0.7.
I think it might do if you get rid of the errors in your smd_if call :-) The value attribute — just like every other attribute — can only take one list of things inside a single pair of quotes, not a set of separate things each in their own quotes. So this is more correct:
...
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq, eq" value="2005-04, 1">
<txp:article limit="1" form="dagboek" sort="Posted asc" />
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
<txp:else />
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq, eq" value="2005-04, 2">
<txp:article limit="3" form="dagboek" sort="Posted asc" />
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
</txp:smd_if>
</txp:smd_if>
...
Also, I thought you wanted to do something different only if you were on the first page? As it stands, your outer ‘else’ statement tests to see if the month variable is set to 2005-04 and pg=1. If that fails (indicating either the month is not 2005-04 or the pg is something higher than 1), it checks to see if the pg is equal to 2. What if it’s 3? Or 4? You’ll get no output.
You might want to consider changing that second smd_if in my example above to:
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq, ge" value="2005-04, 2">
So that it executes the contained statament if pg is greater than or equal to 2. Better still would be this:
<txp:smd_if field="urlvar:month" operator="eq" value="2005-04">
since you already know due to the cascading logic that:
- pg is set to something
- pg is not 1
thus pg must be 2 or higher, so it is not necessary to test it. If you trace through your logic and try different numbers to see which branches execute under which conditions, you’ll find this is true. A bonus of being able to nest the same tag is that your smd_if calls can often be simplified the deeper they get.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#167 2008-11-19 10:01:29
Re: smd_if: Generic multiple if condition tests
gomedia wrote:
…a Feature idea suggestion txp:variable increment & decrement … how about an enhancement to smd_if to add a new operator “is divisible by”
Well, looks like it won’t be getting wings (wet’s argument makes sense and rvm_counter can do the counting for us, as maniqui says) but even so, your idea about a modulo and/or is divisible by is great. I think I can shoehorn that logic into my evil() template system; I’ll try it out when I make some time.
In the meantime, zem_nth could probably be coerced into doing the same thing, but in the interests of having one less plugin to do something that’s probably within reach of this one, I think it’s a plan.
Thanks for the idea.
Last edited by Bloke (2008-11-19 10:02:16)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#168 2008-11-19 11:27:08
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: smd_if: Generic multiple if condition tests
Bloke wrote:
Well, looks like it won’t be getting wings …
Didn’t even get to hatch! I’ll revisit the other options the next time I need to use TXP variables as counters, in the meantime I look forward to your modulo enhancement.
All the best.
Offline
#169 2008-11-19 11:46:07
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hoi Bloke,
Your idea isn’t working properly.
Page 1 is displayed well.
Page 2 is blank.
This is my page template :
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,undefined” value=“2005-04”>
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
<txp:else />
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04, 1”>
<txp:article limit=“1” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
<txp:else />
<txp:smd_if field=“urlvar:month” operator=“eq” value=“2005-04>
<txp:article limit=“3” form=“dagboek” sort=“Posted asc” />
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
</txp:smd_if>
</txp:smd_if>
</txp:smd_if>
And this is the tag trace :
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,undefined” value=“2005-04”>
[<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,undefined” value=“2005-04”>: false]
<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04, 1”>
[<txp:smd_if field=“urlvar:month, urlvar:pg” operator=“eq,eq” value=“2005-04, 1”>: false]
<txp:article limit=“3” form=“dagboek” sort=“Posted asc” />
[SQL (0,000254154205322): select name from txp_section where on_frontpage != ‘1’]
[SQL (0,000365972518921): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and (Category1 IN (‘zwangerschap’) or Category2 IN (‘zwangerschap’)) and Posted like ’2005-04%’ and Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’]
[SQL (0,00075888633728): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and (Category1 IN (‘zwangerschap’) or Category2 IN (‘zwangerschap’)) and Posted like ’2005-04%’ and Section != ‘about’ and Section != ‘contact’ and Section != ‘gallery’ order by Posted asc limit 3, 3]
<txp:ob1_pagination outputlastfirst =“0” outputnextprevious=“0” />
</txp:smd_if>
</txp:smd_if>
As far i can see the right article form is working nl 3 articles a page but on the page i see nothing.
Roelof
Offline
#170 2008-11-19 11:57:18
Re: smd_if: Generic multiple if condition tests
roelof wrote:
Your idea isn’t working properly.
Are you sure? Pay attention to the details and try adding the missing quote around the value in the following line:
<txp:smd_if field="urlvar:month" operator="eq" value="2005-04>
Then see what you get back.
(Edit: could you try and add bc. in front of your code blocks in future posts please, it’s quite hard to trace it when it’s one continuous stream of stuff on the screen, thanks!)
Last edited by Bloke (2008-11-19 11:58:25)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#171 2008-11-19 12:13:30
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hello Bloke,
Still the same.
Here a new tagtrace :
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq,undefined" value="2005-04">
[<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq,undefined" value="2005-04">: false]
<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq,eq" value="2005-04, 1">
[<txp:smd_if field="urlvar:month, urlvar:pg" operator="eq,eq" value="2005-04, 1">: false]
<txp:smd_if field="urlvar:month" operator="eq" value="2005-04">
[<txp:smd_if field="urlvar:month" operator="eq" value="2005-04">: true]
<txp:article limit="3" form="dagboek" sort="Posted asc" />
[SQL (0,000200986862183): select name from txp_section where on_frontpage != '1']
[SQL (0,000367879867554): select count(*) from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and (Category1 IN ('zwangerschap') or Category2 IN ('zwangerschap')) and Posted like '2005-04%' and Section != 'about' and Section != 'contact' and Section != 'gallery']
[SQL (0,000756025314331): select *, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod from textpattern where 1=1 and Status = 4 and Posted <= now() and (now() <= Expires or Expires = 0) and (Category1 IN ('zwangerschap') or Category2 IN ('zwangerschap')) and Posted like '2005-04%' and Section != 'about' and Section != 'contact' and Section != 'gallery' order by Posted asc limit 3, 3]
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
</txp:smd_if>
</txp:smd_if>
</txp:smd_if>
Roelof
Offline
#172 2008-11-19 12:47:20
Re: smd_if: Generic multiple if condition tests
roelof wrote:
Still the same.
Hmm, very odd. As you can see from the tag trace, the smd_if is executing correctly:
- first test is [false] (i.e.
pgis defined) - 2nd test is false (i.e.
pgis not 1) - 3rd test [true] (i.e.
monthis 2005-04).
Then you can see that the article tag is called, executes 3 queries and then ob1_pagination is called.
So as far as smd_if is concerned, it is actually doing everything correctly but for some (other) reason, your article tag and/or ob1_pagination are returning nothing. Weird. It’s kind of out of my league here since it could be any number of things: articles not set to display in that section; not enough articles to display; articles with wrong dates; some random error in your form; …
Sorry, you’ve reached the end of my knowledge I think. Has anyone else got any pearls of wisdom?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#173 2008-11-19 12:53:38
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hai Bloke,
Can it be that for some reasons txp starts the queries on the 3 article.
I.m thinkig yes because the limit shows [3.3] and then txp finds nothing because there are 3 articles now for testing reasons.
Roelof
Offline
#174 2008-11-19 12:56:32
Re: smd_if: Generic multiple if condition tests
roelof wrote:
Can it be that for some reasons txp starts the queries on the 3 article.
I wondered about that 3, 3 thing too. So it’s starting at the 3rd article (I assume because we’re on page 3?) and you have set a limit of 3 articles to display. If there are only 3 articles in total, then that would explain it!
Last edited by Bloke (2008-11-19 12:57:02)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#175 2008-11-19 13:00:52
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Oke,
I found the solution.
If a do this <txp:article limit=“3” form=“dagboek” offset=”-2” sort=“Posted asc” /> then 2 articles are displayed.
On some way txp starts counting wrong.
Roelof
Offline
#176 2008-11-20 09:07:52
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: smd_if: Generic multiple if condition tests
Hai Bloke,
Still some problems with the use of this plugin.
My page template is like this :
<div id="content">
<txp:if_section name=",default">
<txp:if_category name="zwangerschap,jaar1,jaar2,jaar3,jaar4">
<txp:smd_if field="urlvar:month" operator="eq" value="2005-04">
<txp:smd_if field="urlvar:pg" operator="ge" value="2">
<txp:article limit="2" form="dagboek" sort="Posted asc" />
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" />
<txp:else />
<txp:article limit="1" form="dagboek" sort="Posted asc" />
<txp:ob1_pagination outputlastfirst ="0" outputnextprevious="0" maximumtabs="4"/>
</txp:smd_if>
<txp:else />
<txp:smd_if field="urlvar:month" operator="defined">
<txp:article limit="5" form="dagboek" sort="Posted asc" />
</smd_if>
</smd_if>
<txp:else />
<txp:article_custom section="voorpagina" form="default" />
</txp:if_category>
</txp:if_section>
</div>
But now it’s schows nothing at all.
Txp stops at the <div id= “content”>
Do you have any clue why ?
Roelof
Offline
#177 2008-11-20 09:38:07
Re: smd_if: Generic multiple if condition tests
roelof wrote:
</smd_if>
Details again: should be </txp:smd_if> (x2).
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#178 2008-11-20 16:39:57
Re: smd_if: Generic multiple if condition tests
I have a site which will, over time, accumulate multiple articles of the same name (different url-only title) — short bios with where the title is the person’s name. In the search results, if that person’s name is searched on, I’d like to return only the most recent of those articles. I feel like this plugin is the way there…but not sure how. Or maybe there is a simpler way?
Any help appreciated.
Offline
#179 2008-11-20 17:42:47
Re: smd_if: Generic multiple if condition tests
nabrown78 wrote:
I have a site which will, over time, accumulate multiple articles of the same name (different url-only title) — short bios with where the title is the person’s name. In the search results, if that person’s name is searched on, I’d like to return only the most recent of those articles. I feel like this plugin is the way there…but not sure how. Or maybe there is a simpler way?
Could you clarify your requirements? You need only sorting search results by date, when newest articles are the first in list?
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
#180 2008-11-20 17:58:52
Re: smd_if: Generic multiple if condition tests
Hi Victor -
Let’s say I have two biographic articles about Joe Schmoe, and three biographic articles about Joe Plumber. If someone does a search for “Joe” I want to display only the most recent article about Joe Schmoe, and only the most recent article about Joe Plumber. Does that make sense? At the moment I can’t see a straightforward way to achieve it.
Offline