Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-01-09 16:21:14

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

[howto] Conditional code for next/prev articles using variables

This shows the next and previous links only if they exist, allowing the addition of blocks of code within the conditional statement, rather than just a link to the next or previous article.

It’s extremely useful if the prev/next tags on your site need to include layout code/structure.

<txp:variable name="hasprev" value='<txp:prev_title />' />
<txp:variable name="hasnext" value='<txp:next_title />' />

<txp:if_variable name="hasnext" value="">
                    <p class="quiet">This is the latest article</p>
<txp:else />
                    <p class="next"><txp:link_to_next ><txp:next_title /></txp:link_to_next></p>   
</txp:if_variable>

<txp:if_variable name="hasprev" value="">
                    <p class="quiet">No previous articles</p>
<txp:else />
                    <p class="prev"><txp:link_to_prev ><txp:prev_title /></txp:link_to_prev></p>
</txp:if_variable>

Offline

Board footer

Powered by FluxBB