Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Customise the next/prev links
Probably a simple solution available, but currently escaping me. I have this code to customise the next/prev links for individual articles:
<p><a href="<txp:link_to_prev />" title="<txp:prev_title />" class="button orange">« <txp:prev_title /></a>
<a href="<txp:link_to_next />" title="<txp:next_title />" class="button orange"><txp:next_title /> »</a></p>
Problem is, if we are on the latest article page the button still displays with this in it: »
I know why of course – using the default method <txp:link_to_prev><txp:prev_title /></txp:link_to_prev>
would result in a link that would not display, because showalways=
is off by default.
Anyone know a way around this? Els? ;-)
Offline
#2 2009-09-06 19:36:10
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Customise the next/prev links
jstubbs wrote:
Anyone know a way around this? Els? ;-)
Sure :) Something like this?
<txp:variable name="prev" value='<txp:link_to_prev />' />
<txp:variable name="next" value='<txp:link_to_next />' />
<p><txp:if_variable name="prev" value="">
<txp:else />
<a href="<txp:link_to_prev />" title="<txp:prev_title />" class="button orange">« <txp:prev_title /></a>
</txp:if_variable>
<txp:if_variable name="next" value="">
<txp:else />
<a href="<txp:link_to_next />" title="<txp:next_title />" class="button orange"><txp:next_title /> »</a>
</txp:if_variable></p>
You may have to replace the link_to_prev/next tags in the value
attribute with the prev/next_title tags, but I’m guessing it will work either way.
Offline
Re: Customise the next/prev links
It’s times like these I always think <txp:if_last_article>
should come to the rescue but — despite its Textbook entry stating it can be used in both list and individual article context — I’ve never been able to reliably detect the first/last article when showing an individual article. Perhaps I’m just being a bit dim.
The only way I can think of is the has trick:
<txp:variable name="has_more">
<txp:link_to_next />
</txp:variable>
<txp:if_variable name="has_more">
<p>
<a href="<txp:link_to_next />" title="<txp:next_title />" class="button orange"><txp:next_title /> »</a>
</p>
</txp:if_variable>
And repeat for the ‘prev’ case. If someone posts a cooler solution, there’ll be at least two happy bunnies on the forum!
Edit: of course Els was faster… and her solution actually works ;-)
Last edited by Bloke (2009-09-06 19:38:43)
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
#4 2009-09-06 19:46:10
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Customise the next/prev links
Using the variable tag as a container tag has the advantage that you don’t have to worry about using the right (single) quotes (at least if you’re not nesting the attibutes more than one level deep) ;) I always forget it can be used as a container as well, thanks for the reminder, Stef!
Offline
Re: Customise the next/prev links
Els wrote:
I always forget it can be used as a container as well
I’d forgotten too! (maniqui reminded me the other day)
The six million dollar question though, when using it in this has configuration — is whether the container system actually works. Would a space at the start of the inside tag and/or a newline in a multi-line set of tags cause the value
attribute to contain a space/newline and thus render the <txp:if_variable>
test useless? Hmmm…
Last edited by Bloke (2009-09-06 20:00:05)
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
#6 2009-09-06 20:20:07
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Customise the next/prev links
Bloke wrote:
The six million dollar question
OK I’m in! ;)
This works:
<txp:variable name="has_more"><txp:link_to_next /></txp:variable>
<txp:if_variable name="has_more" value="">
<txp:else />
blah
</txp:if_variable>
and this doesn’t work:
<txp:variable name="has_more">
<txp:link_to_next />
</txp:variable>
<txp:if_variable name="has_more" value="">
<txp:else />
blah
</txp:if_variable>
So at the moment I think it’s safer to keep using the single tag…
Last edited by els (2009-09-06 20:22:58)
Offline
Re: Customise the next/prev links
Els
Cool, that proves it then; inline is the way forward when doing this kind of thing. Nice one.
Your six million is on its way. I took the liberty of employing Mr Umbotou of Nigeria as a go-between. He’ll be contacting you via e-mail claiming you’re his next of kin and will deliver the funds when you confirm to him your bank details, PIN, social security number, and head circumference ;-)
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
#8 2009-09-07 16:10:15
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Customise the next/prev links
Thank you Stef! Since I’d trust you with my life I will dutifully provide all information the first Nigerian that contacts me will ask for, even if his name turns out to be a different one (because I can imagine it’s easy to miss-spell those foreign names).
You made my day :-D
Offline
Re: Customise the next/prev links
Without meaning to open a can of worms, just wondering why you’d choose this option over the shorter chh_if_data
(which I believe will also do the job).
- longevity (avoid plugins breaking when you upgrade)?
- is there any inherent performance advantage in sticking to native tags?
- summat else less boring instead?
Offline
Re: Customise the next/prev links
Stuart, using chh_if_data would indeed work and with less code, but it is a plugin.
Els and Stef – thanks for the code and the entertainment along the way! I had been looking for a non-variable solution but I think in this case its the only remedy, since we have customised the links…
This does work and I will soon add it to TXP Tips for others’ enjoyment…thanks!
<txp:variable name="prev" value='<txp:link_to_prev />' />
<txp:variable name="next" value='<txp:link_to_next />' />
<p><txp:if_variable name="prev" value="">
<txp:else />
<a href="<txp:link_to_prev />" title="<txp:prev_title />" class="button orange">« <txp:prev_title /></a>
</txp:if_variable>
<txp:if_variable name="next" value="">
<txp:else />
<a href="<txp:link_to_next />" title="<txp:next_title />" class="button orange"><txp:next_title /> »</a>
</txp:if_variable></p>
Offline
Re: Customise the next/prev links
Thanks Els – here you go – customising the next prev links
Offline
Pages: 1