Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-02-19 14:59:46
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
pagination problem
Hello,
I have this problem.
Every article has a custom field named pagenr with for example the value 2
When I do on the page template.
<txp:custom field named=“pagenr” value=“3”>
Will the value 2 which is in the database be overwritten by the new value or will it be the old value.
Roelof
Last edited by roelof (2010-02-19 15:32:21)
Offline
Re: pagination problem
roelof wrote:
<txp:custom field named=“pagenr” value=“3”>
Eh? There’s no such tag. You appear to have combined the if_custom_field and custom_field tags to make a fictitious hybrid :-)
Last edited by Bloke (2010-02-19 15:09:18)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#3 2010-02-19 15:14:14
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination problem
Hello Bloke,
You’re right. I combined custom field with txp:variable
The script im working is not doing what it supposed to do , so back to the drawing table.
Roelof
Offline
#4 2010-02-19 15:38:15
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination problem
Hello,
I have this problem.
I have several articles in a month. Every article has a custom field with the name “pagenumber”
I use a script so every pagenumber is only displayed one time.
Now the problem.
In september 2005 I have pagination of 17 pages where only a pagination of 11 can be displayed.
So i thought I make a script which do the following.
when it’s sept 2005 which has 17 pages.
When I read pages 1 till 4 I have to see a pagination of 1 till 11
When I read pages 4 till 8 I have to see a pagination of the pagenumber -2 till that number + 10
When I read pages 9 till 17 I see a pagination of 6 till 17.
Alll the other months I have to see all the pagination.
Roelof
Can this be done ?
Offline
#5 2010-02-19 16:20:35
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination problem
I have made this script :
<txp:smd_if field="txpvar:totpages" operator="ge" value="11" >
<txp:smd_if field="urlvar:pg,urlvar:pg,txpvar:firstpage" operator="ge,le,none" value="4,8,0" >
<txp:variable name="firstpage" value='<txp:variable name="pagenumber" />' />
<txp:adi_calc name="firstpage" subtract="2" />
<txp:variable name="lastpage" value='<txp:variable name="firstpage"/>' />
<txp:adi_calc name="lastpage" add="10"/>
</txp:smd_if>
<txp:smd_if field="urlvar:pg,txpvar:firstpage" operator="ge,none" value="8,0" >
<txp:variable name="firstpage" value="6" />
<txp:variable name="lastpage" value="17"/>
</txp:smd_if>
<txp:smd_if field="urlvar:pg,txpvar:firstpage" operator="le,none" value="4,0" >
<txp:variable name="firstpage" value="1" />
<txp:variable name="lastpage" value="11"/>
</txp:smd_if>
<txp:smd_if field="urlvar:pg" operator="undefined" >
<txp:variable name="firstpage" value="1" />
<txp:variable name="lastpage" value="11"/>
</txp:smd_if>
</txp:smd_if>
<txp:variable name="meerdan1pagina" value='<txp:article_custom category=''<txp:variable name="category" />'' section="articles" month=''<txp:page_url type="month" />'' pagenr="2" limit="1"><txp:title /></txp:article_custom>' />
<!-- als er tenminste één artikel op pagina 2 staat, is er meer dan 1 pagina -->
<ul class="navlist" id="navlist"><txp:article_custom form="dagboek" month='<txp:page_url type="month" />' category='<txp:variable name="category" />' section="articles" sort="custom_1 + 0 asc, posted asc" limit="99">
<txp:if_variable name="meerdan1pagina" value="">
<!-- geen artikel op pagina 2, dus is er maar 1, dus laten we paginanr. niet zien -->
<txp:else />
<txp:if_different>
<li<txp:if_variable name="pagenumber" value='<txp:custom_field name="pagenr" />'> class="here"<txp:else /><txp:if_variable name="pagenumber" value=""><txp:if_custom_field name="pagenr" val="1">class="here"</txp:if_custom_field></txp:if_variable></txp:if_variable>>
<txp:smd_if field="txpvar:totpages" operator="ge" value="11" ><txp:smd_if field="my_custom_field_pagenr" operator="le" value='<txp:variable name="firstpage"/>'><txp:variable name="pagenumber" value='<txp:variable name="firstpage"/> '/></txp:smd_if><txp:smd_if field="my_custom_field_pagenr" operator="ge" value='<txp:variable name="lastpage"/>'><txp:variable name="pagenumber" value='<txp:variable name="lastpage"/>'/></txp:smd_if><a href="?c=<txp:page_url type="c" />&month=<txp:page_url type="month" />&pg=<txp:variable name="pagenumber" />"><txp:variable name="pagenumber" /></a> </li><txp:else />
<a href="?c=<txp:page_url type="c" />&month=<txp:page_url type="month" />&pg=<txp:page_url type="pg" />"><txp:custom_field name="pagenr"/></a></li></txp:smd_if>
</txp:if_different>
</txp:if_variable>
</txp:article_custom>
</ul>
</txp:if_variable>
</txp:if_section>
but on all months the url contains no pagenumber and on sept. 2005 all pagenumbers are 11.
Roelof
Offline
#6 2010-02-19 17:48:57
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination problem
Tag foutmelding <txp:variable name=paginanummer /> -> Textpattern Warning: Attribuut waarden moeten tussen aanhalingstekens on line 984
I understand that you want to strip the whitespace from the page’s source code, but it makes it harder to troubleshoot your code.
My guess is that you put too many tags inside the if_different tags.
Oh, and if you post code that ends with a lot of closing tags, you’d better include the opening tags as well, otherwise it’s impossible to tell whether you closed your tags correctly.
Last edited by els (2010-02-19 18:11:52)
Offline
#7 2010-02-19 18:45:17
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination problem
Hello Els,
Here the whole code:
<txp:article pgonly="1" limit="1" /><!-- om de foutmelding dat er geen article tag is te voorkomen, doet verder niets -->
<txp:if_section name="default">
<txp:variable name="monthpage" value='<txp:page_url type="month" />' />
<txp:variable name="pagenumber" value='<txp:page_url type="pg" />' />
<txp:variable name="category" value='<txp:page_url type="c" /> '/>
<txp:variable name="totpages" value='<txp:article_custom category=''<txp:category />'' month=''<txp:page_url type="month" />'' sort="Posted desc" limit="1"><txp:custom_field name="pagenr" /></txp:article_custom>' />
<txp:variable name="firstpage" value="0" />
<!-- check if we're on a monthly archive page or not -->
<txp:if_variable name="monthpage" value="">
<!-- no, this is the frontpage -->
<txp:article_custom section="voorpagina" form="default" />
<txp:else />
<txp:article_custom month='<txp:page_url type="month" />' section="articles" category='<txp:page_url type="c" />' pagenr='<txp:if_variable name="pagenumber" value="">1<txp:else /><txp:page_url type="pg" /></txp:if_variable>' limit="999" form="dagboek" sort="Posted asc" />
<!-- pagination -->
<txp:smd_if field="txpvar:totpages" operator="ge" value="11" >
<txp:smd_if field="urlvar:pg,urlvar:pg,txpvar:firstpage" operator="ge,le,none" value="4,8,0" >
<txp:variable name="firstpage" value='<txp:variable name="pagenumber" />' />
<txp:adi_calc name="firstpage" subtract="2" />
<txp:variable name="lastpage" value='<txp:variable name="firstpage"/>' />
<txp:adi_calc name="lastpage" add="10"/>
</txp:smd_if>
<txp:smd_if field="urlvar:pg,txpvar:firstpage" operator="ge,none" value="8,0" >
<txp:variable name="firstpage" value="6" />
<txp:variable name="lastpage" value="17"/>
</txp:smd_if>
<txp:smd_if field="urlvar:pg,txpvar:firstpage" operator="le,none" value="4,0" >
<txp:variable name="firstpage" value="1" />
<txp:variable name="lastpage" value="11"/>
</txp:smd_if>
<txp:smd_if field="urlvar:pg" operator="undefined" >
<txp:variable name="firstpage" value="1" />
<txp:variable name="lastpage" value="11"/>
</txp:smd_if>
</txp:smd_if>
<txp:variable name="meerdan1pagina" value='<txp:article_custom category=''<txp:variable name="category" />'' section="articles" month=''<txp:page_url type="month" />'' pagenr="2" limit="1"><txp:title /></txp:article_custom>' />
<!-- als er tenminste één artikel op pagina 2 staat, is er meer dan 1 pagina -->
<ul class="navlist" id="navlist"><txp:article_custom form="dagboek" month='<txp:page_url type="month" />' category='<txp:variable name="category" />' section="articles" sort="custom_1 + 0 asc, posted asc" limit="99">
<txp:if_variable name="meerdan1pagina" value="">
<!-- geen artikel op pagina 2, dus is er maar 1, dus laten we paginanr. niet zien -->
<txp:else />
<txp:if_different>
<li
<txp:if_variable name="pagenumber" value='<txp:custom_field name="pagenr" />'>
class="here"
<txp:else />
<txp:if_variable name="pagenumber" value="">
<txp:if_custom_field name="pagenr" val="1">
class="here"
</txp:if_custom_field>
</txp:if_variable>
</txp:if_variable>>
<txp:smd_if field="txpvar:totpages" operator="ge" value="11" >
<txp:smd_if field="my_custom_field_pagenr" operator="le" value='<txp:variable name="firstpage"/>'>
<txp:variable name="pagenumber" value='<txp:variable name="firstpage"/> '/>
</txp:smd_if>
<txp:smd_if field="my_custom_field_pagenr" operator="ge" value='<txp:variable name="lastpage"/>'>
<txp:variable name="pagenumber" value='<txp:variable name="lastpage"/>'/>
</txp:smd_if>
<a href="?c=<txp:page_url type="c" />&month=<txp:page_url type="month" />&pg=<txp:variable name="pagenumber" />"><txp:variable name="pagenumber" /></a> </li>
<txp:else />
<a href="?c=<txp:page_url type="c" />&month=<txp:page_url type="month" />&pg=<txp:page_url type="pg" />">
<txp:custom_field name="pagenr"/></a></li>
</txp:smd_if>
</txp:if_different>
</txp:if_variable>
</txp:article_custom>
</ul>
</txp:if_variable>
</txp:if_section>
Roelof
Last edited by roelof (2010-02-19 18:50:49)
Offline
#8 2010-02-19 18:55:31
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination problem
Thank you. Intersting code. I’ll have another look after supper if you don’t mind. Can you tell me what operator=“none” does, I’m not so familiar with smd_if.
Offline
#9 2010-02-19 19:40:56
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination problem
Hello Els,
Of course.
Operator none is wrong , it must be not.
Wierd that I get the good outcome.
But I will change it.
Roelof
Offline
#10 2010-02-19 20:33:41
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination problem
Roelof, do you have two custom fields: ‘pagenr’ and ‘my_custom_field_pagenr’? What is in the second?
Offline
#11 2010-02-19 21:16:51
- roelof
- Member
- Registered: 2005-03-27
- Posts: 647
Re: pagination problem
Hello Els,
It’s the same.
Smd_if can only work with custom fields this way.
Roelof
Offline
#12 2010-02-19 21:37:00
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: pagination problem
Thank you. I went through the first half of your code, and I understand what you want it to do, but it’s not doing that. I put my remarks inside the code (in capitals), so don’t copy/paste it ;) What I did was writing down in ‘human’ language what the tags exactly do, that’s always a good way to check your code. If it doesn’t help you, choose a page number and try and follow how the variables, calculations and conditionals are affecting it.
Remarks are in Dutch – because it’s complex enough as it is, and I don’t expect anyone to be seriously interested in a translation ;)
I think what you have in mind can definitely be done, but I’m not going to rewrite the code for you. I hope my remarks will help you see why it doesn’t work.
“Back to the drawing table”, Roelof ;)
<txp:article pgonly="1" limit="1" /><!-- om de foutmelding dat er geen article tag is te voorkomen, doet verder niets -->
<txp:if_section name="default">
<txp:variable name="monthpage" value='<txp:page_url type="month" />' />
<txp:variable name="pagenumber" value='<txp:page_url type="pg" />' />
<txp:variable name="category" value='<txp:page_url type="c" /> '/>
<txp:variable name="totpages" value='<txp:article_custom category=''<txp:category />'' month=''<txp:page_url type="month" />'' sort="Posted desc" limit="1"><txp:custom_field name="pagenr" /></txp:article_custom>' />
VAR:TOTPAGES WORDT HET HOOGSTE PAGINANUMMER VAN DEZE MAAND = TOTAAL AANTAL PAGINA'S
<txp:variable name="firstpage" value="0" />
VAR:FIRSTPAGE WORDT 0
<!-- check if we're on a monthly archive page or not -->
<txp:if_variable name="monthpage" value="">
<!-- no, this is the frontpage -->
<txp:article_custom section="voorpagina" form="default" />
<txp:else />
<txp:article_custom month='<txp:page_url type="month" />' section="articles" category='<txp:page_url type="c" />' pagenr='<txp:if_variable name="pagenumber" value="">1<txp:else /><txp:page_url type="pg" /></txp:if_variable>' limit="999" form="dagboek" sort="Posted asc" />
<!-- pagination -->
<txp:smd_if field="txpvar:totpages" operator="ge" value="11">
ALS ER 11 OF MEER PAGINA'S ZIJN
<txp:smd_if field="urlvar:pg,urlvar:pg,txpvar:firstpage" operator="ge,le,not" value="4,8,0">
ALS 1. HUIDIGE PAGINANR. GROTER DAN OF GELIJK AAN 4
EN 2. HUIDIGE PAGINANR. KLEINER DAN OF GELIJK AAN 8
EN 3. VAR:FIRSTPAGE NIET GELIJK AAN 0 (GEEFT ALTIJD FALSE WANT DIE HEB JE EERDER OP 0 GEZET!)
<txp:variable name="firstpage" value='<txp:variable name="pagenumber" />' />
VAR:FIRSTPAGE WORDT HUIDIGE PAGINANUMMER
<txp:adi_calc name="firstpage" subtract="2" />
VAR:FIRSTPAGE WORDT HUIDIGE PAGINANR. -/- 2
<txp:variable name="lastpage" value='<txp:variable name="firstpage"/>' />
VAR:LASTPAGE = HUIDIGE PAGINANR. -/- 2
<txp:adi_calc name="lastpage" add="10"/>
VAR:LASTPAGE WORDT HUIDIGE PAGINANUMMER -/- 2 + 10
</txp:smd_if>
<txp:smd_if field="urlvar:pg,txpvar:firstpage" operator="ge,not" value="8,0">
ALS 1. HUIDIGE PAGINANR. GROTER DAN OF GELIJK AAN 8 (DIT OVERLAPT MET DE EERSTE: KLEINER DAN OF GELIJK AAN 8)
EN 2. VAR:FIRSTPAGE (= HUIDIGE PAGINANR. - 2) NIET GELIJK AAN 0
=> HUIDIGE PAGINAR. NIET GELIJK AAN 2
??? DENK NIET DAT DE TWEEDE ZO BEDOELD IS ???
<txp:variable name="firstpage" value="6" />
VAR:FIRSTPAGE WORDT 6
<txp:variable name="lastpage" value="17"/>
VAR:LASTPAGE WORDT 17
</txp:smd_if>
<txp:smd_if field="urlvar:pg,txpvar:firstpage" operator="le,not" value="4,0">
ALS 1. HUIDIGE PAGINANR. KLEINER DAN OF GELIJK AAN 4 (DIT OVERLAPT MET DE EERSTE: GROTER DAN OF GELIJK AAN 4)
EN 2. VAR:FIRSTPAGE (= HUIDIGE PAGINANR. -/- 2) NIET GELIJK AAN 0
=> HUIDIGE PAGINANR. NIET GELIJK AAN 2
???
<txp:variable name="firstpage" value="1" />
VAR:FIRSTPAGE WORDT 1
<txp:variable name="lastpage" value="11"/>
VAR:LASTPAGE WORDT 11
</txp:smd_if>
<txp:smd_if field="urlvar:pg" operator="undefined">
ALS ER GEEN PAGINANR. IS (EERSTE PAGINA)
<txp:variable name="firstpage" value="1" />
VAR:FIRSTPAGE WORDT 1
<txp:variable name="lastpage" value="11"/>
VAR:LASTPAGE WORDT 11
</txp:smd_if>
HIER BEN IK GESTOPT, HEEFT GEEN ZIN OM NAAR DE REST TE KIJKEN ALS DIT EERSTE DEEL NIET WERKT.
Offline