Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2006-10-05 21:14:07
- minusf
- Member
- Registered: 2005-02-15
- Posts: 104
conditional txp:newer / txp:older
hi there,
i am sorry if this came up before, searches turned up nothing for me.
i would like to make txp:never and txp:older conditional.
when there is no newer/older article/page, don’t show the tag/link
prev | next
if there is no prev:
| next
or if there is no next:
prev |
this is not very professional, is it..
of course the same for prev_link, etc.
i am sure there is a way, i just don’t know it.
Last edited by minusf (2006-10-05 21:15:06)
we is experts™
Offline
#2 2006-10-06 02:24:48
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: conditional txp:newer / txp:older
Check out the available conditional tags <a href=“http://textbook.textpattern.net/wiki/index.php?title=Txp:if_first_article”>if first article</a> and <a href=“http://textbook.textpattern.net/wiki/index.php?title=Txp:if_last_article”>if last article</a>
Offline
#3 2006-10-06 03:10:36
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: conditional txp:newer / txp:older
I thought they behaved that way by default?
Offline
#4 2006-10-06 05:35:40
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: conditional txp:newer / txp:older
Rick: I think he’s referring to the |
that he puts in between the two – when one of the links disappears, the |
remains in the page, so it looks a little less pretty. :)
Offline
#5 2006-10-07 15:33:09
- minusf
- Member
- Registered: 2005-02-15
- Posts: 104
Re: conditional txp:newer / txp:older
masa wrote:
Check out the available conditional tags <a href=“http://textbook.textpattern.net/wiki/index.php?title=Txp:if_first_article”>if first article</a> and <a href=“http://textbook.textpattern.net/wiki/index.php?title=Txp:if_last_article”>if last article</a>
is it possible to nest these? it doens’t seem to work for me.
i need to distuingish if an article is individual and first and the other
cases. something like (changed angle brackets to square)
<pre>
<code>
[txp:if_individual_article]
[txp:if_first_article]
[txp:link_to_next][txp:next_title][/txp:link_to_next]
[txp:else /]
[txp:link_to_prev][txp:prev_title /][/txp:link_to_prev] |
[txp:link_to_next][txp:next_title /][/txp:link_to_next]
[/txp:if_first_article]
[txp:else /]
[txp:if_first_article]
[txp:older]older[/txp:older]
[txp:else /]
[txp:older]older[/txp:older] |
[txp:newer]newer[/txp:newer]
[/txp:if_first_article]
[/txp:if_individual_article]
</code>
</pre>
i just found out that i will have to deal with if_last_article also.
this is getting horribli unreadable..
is there a nice tidy solution for this? or is it not worth leaving the “|”? :)
Last edited by minusf (2006-10-07 15:40:48)
we is experts™
Offline
#6 2006-10-07 16:11:17
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: conditional txp:newer / txp:older
Try this:
deleted (code was wrong)
Last edited by Mary (2006-10-10 10:12:56)
Offline
#7 2006-10-09 20:01:39
- minusf
- Member
- Registered: 2005-02-15
- Posts: 104
Re: conditional txp:newer / txp:older
thanks, gotta put on my coding hat again, so i don’t overcomplicate stuff :)
your version gave me some ideas but it doesn’t deal with last_articles..
also my main page uses the “default” section, but the individual articles use
the “news” section. so i am interpreting stuff correctly, i don’t need the
if_individual_article stuff, i can put specific cases into specific section’s representation, right?
thanks for the tips.
we is experts™
Offline
#8 2006-10-09 20:48:34
- minusf
- Member
- Registered: 2005-02-15
- Posts: 104
Re: conditional txp:newer / txp:older
ok, i messed around some more.
my royal pain is the first/last dichotomy:
i need a middle way. i need to know when an article is not first and last,
obviously, that’s the point where i need the item separator.
textpattern.net is absolutely ambigious when it comes to nesting these if’s,
so i tried the only way i came up with to determine using if_last_article/if_first_article (pseudocode):
bc..
<txp:if_first_article>
<txp:else />
<txp:if_last_article>
<txp:else />
i am not first and last
</txp:if_last_article>
</txp:if_first_article>
but this doesn’t work. so i guess the if’s cannot be nested like this.
what about an if_middle_article? ;-)
ps. how the hell do i quote code? even the example from the textile site
isn’t working.. gr..
Last edited by minusf (2006-10-09 20:55:16)
we is experts™
Offline
#9 2006-10-09 21:55:04
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: conditional txp:newer / txp:older
Another ‘solution’, or rather workaround (in 4.0.4):
<code>
<txp:older showalways=“1”>prev</txp:older> | <txp:newer showalways=“1”>next</txp:newer>
</code>
This will show ‘prev’ or ‘next’ but not hyperlinked when there are no older or newer articles.
You might even be able to do this:
<code>
<txp:older showalways=“1”><txp:if_last_article>no previous articles<txp:else />prev</txp:if_last_article></txp:older> | <txp:newer showalways=“1”><txp:if_first_article>no newer articles<txp:else />next</txp:if_first_article></txp:newer>
</code>
Offline
#10 2006-10-09 22:13:53
- minusf
- Member
- Registered: 2005-02-15
- Posts: 104
Re: conditional txp:newer / txp:older
interesting alternative. placeholders are sometimes a good thing.
and sometimes confuse novice users :)
i have submitted a patch on the dev mailing list for if_middle_article…
i know it’s too close to release, if useful perhaps it will get in at some time.
it would allow:
bc..
<p><txp:link_to_prev><txp:prev_title /></txp:link_to_prev>
<txp:if_middle_article> | </txp:if_middle_article>
<txp:link_to_next><txp:next_title /></txp:link_to_next></p>
puts the “|” only when in an article which is neither last or first.
i think it is handy to put delimiters between txp:older / txp:never
and / or txp:link_to_prev / txp:link_to_next for people who aren’t
dealing with this using css, e.g. want a very simple solution…
the else case is undefined ;-)
we is experts™
Offline
#11 2006-10-09 22:28:05
- minusf
- Member
- Registered: 2005-02-15
- Posts: 104
Re: conditional txp:newer / txp:older
Els wrote:
Another ‘solution’, or rather workaround (in 4.0.4):
<code>
<txp:older showalways=“1”>prev</txp:older> | <txp:newer showalways=“1”>next</txp:newer>
</code>
actually i like your solution quite a bit.
but i think this showalways is not documented in the wiki, is it?
interesting, after pasting in both your solutions i get the following notices:
<pre>
tag_error <txp:if_last_article> -> Textpattern Notice: error_article_context on line 1820
tag_error <txp:if_first_article> -> Textpattern Notice: error_article_context on line 1820
</pre>
we is experts™
Offline
#12 2006-10-10 03:27:55
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: conditional txp:newer / txp:older
Els is referring to ability only available in svn (the next maintenance release of Textpattern). TextBook is not exactly a comprehensive resource, and it takes time for it to be caught up.
Oh yeah, I forgot about not being on the last page too. I saw your patch on the dev list, and yes, a proper tag for it is the best possible way to go about it. So, until the patch or something similar is added, you’ve got two options:
- Turn the patch into a plugin.
- Do something like the following:
deleted (code was wrong)
It’s messy, but it should work.
The tag error doesn’t make much sense, are you sure you’re using older/newer on your page, and not link_to_next/link_to_prev (which can only be called from an article form)?
Last edited by Mary (2006-10-10 10:12:10)
Offline