Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2025-12-31 08:37:38

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,500
Website GitHub

Re: link_to_next not working

The behaviour of link_to_* changed a while ago. It now automatically changes context inside the container tag to “previous” or “next” article on your behalf. So you no longer need to use prev_title or next_title tags. In fact, as you found, doing so will fetch the title of the article one beyond the article you expect.

Short answer: swap your prev_title and next_title tags for just <txp:title /> and it’ll work.


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

#32 2025-12-31 09:35:06

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

Re: link_to_next not working

Bloke wrote #342039:

Short answer: swap your prev_title and next_title tags for just <txp:title /> and it’ll work.

Does this mean that prev_title and next_title tags are deprecated? If so, we should mark them as such in the Tag reference index.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#33 2025-12-31 11:59:00

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,500
Website GitHub

Re: link_to_next not working

colak wrote #342040:

Does this mean that prev_title and next_title tags are deprecated?

No. There are situations where you want to show the previous or next title but not link to them (e.g. to tease future articles). So these tags are useful outside of link_to_* context.


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

#34 2026-01-05 19:49:42

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,278
Website Mastodon

Re: link_to_next not working

Links: Prev Next

I am still having issues. If I hand HTML code the links to prev/next all is working fine:

<nav class="portfolio__meta__nav"> 
    <a href="https://textism.ca/portfolio/bicilogic-on-two-wheels" class="portfolio__meta__prev">Previous</a>
    <a href="https://textism.ca/portfolio/ponzano-veneto" class="portfolio__meta__next">Next</a>
</nav>

but if I enter this

<nav class="portfolio__meta__nav">
    <div class="prevNext">
        <span id="linkToPrev"><txp:link_to_prev>&#8592;&nbsp;</txp:link_to_prev></span>
        <span id="linkToNext"><txp:link_to_next>&nbsp;&#8594;</txp:link_to_next></span>
    </div>
</nav>

the results outputs one Arrow Left on the first and the last article and two Arrows Left on the middle article. And on the far right side, but so only on the last article is the single arrow correctly pointing to previous.

and if I don’t use this <nav class="portfolio__meta__nav"> the arrows etc are all correct except that I don’t have the big Arrows used by the class Portfolio. I would be happy to add the arrows as images in the last example and worry about placing them to the Right area as opposed to the default on the left hand side.

It must be a simple solution but it has me stumped…


…. texted postive

Offline

#35 2026-01-05 22:02:40

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,225
Website GitHub

Re: link_to_next not working

I’m not sure what your desired outcome is. If you want to always show the arrows, even if there is no article preceding the first or following the last, you can use the attribute showalways="1" on your link_to_next and link_to_prev tags.

If you want to avoid having empty span tags when there is no link, you can use the wraptag and class attributes so that they are omitted if there is no relevant preceding/following article, e.g.

<nav class="portfolio__meta__nav">
    <div class="prevNext">
        <txp:link_to_prev wraptag="span" class="linkToPrev">&#8592;&nbsp;</txp:link_to_prev>
        <txp:link_to_next wraptag="span" class="linkToNext">&nbsp;&#8594;</txp:link_to_next>
    </div>
</nav>

TXP Builders – finely-crafted code, design and txp

Offline

#36 2026-01-05 22:08:46

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,278
Website Mastodon

Re: link_to_next not working

to answer my own question I fiddled around and got this to work correctly.

<nav class="portfolio__meta__nav"> 
    <a href="<txp:link_to_prev />" title="<txp:prev_title />" class="portfolio__meta__prev">  </a>
    <a href="<txp:link_to_next />" title="<txp:next_title />" class="portfolio__meta__next">  </a>
</nav>

I just tried a variety of combos until it worked… a pure TXP solution would have been better , but for now I am happy.

UPDATE
PS tried another code but the only issue is that there is a break line in the output of the two links… how / where can I insert break="" so there no newline in the output of the links:

<nav class="portfolio__meta__nav"> 
    <txp:variable name="prev" value='<txp:link_to_prev />' />
    <txp:variable name="next" value='<txp:link_to_next />' />
    <txp:if_variable name="prev" value="">
    <txp:else />
         <a href="<txp:link_to_prev />" title="<txp:prev_title />" class="portfolio__meta__prev"> <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="portfolio__meta__next"><txp:next_title /> </a>
    </txp:if_variable>
</nav>

I was not able to find any info in the documentation


…. texted postive

Offline

#37 2026-01-05 22:37:52

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,225
Website GitHub

Re: link_to_next not working

Wrapping your links inside txp:link_to_prev / txp:link_to_next would prevent them outputting anything if there is no link, avoiding the need for your variable test, but … unfortunately it won’t put your desired class name on the link, only a wrapping tag.

Two options spring to mind. Use the regular tags and change your css:

<nav class="portfolio__meta__nav">
    <txp:link_to_prev><txp:prev_title /></txp:link_to_prev>
    <txp:link_to_next ><txp:next_title /></txp:link_to_next>
</nav>

and change in your css:

.portfolio__meta__prev {    --->   .portfolio__meta__nav a[rel="prev"] {
.portfolio__meta__next {    --->   .portfolio__meta__nav a[rel="next"] {

Or version 2, use txp:evaluate to test if a tag inside the container provides any output, e.g.

<nav class="portfolio__meta__nav"> 
    <txp:evaluate test="link_to_prev">
         <a href="<txp:link_to_prev />" title="<txp:prev_title />" class="portfolio__meta__prev"> <txp:prev_title /></a>
    </txp:evaluate>
    <txp:evaluate test="link_to_next">
        <a href="<txp:link_to_next />" title="<txp:next_title />" class="portfolio__meta__next"><txp:next_title /> </a>
    </txp:evaluate>
</nav>

Another tip – not relevant to the code snippets I posted here – but possibly a reason why you are getting gaps in your earlier code:

You can simplify your “if empty … else …”

<txp:if_variable name="myvar" value="">
<txp:else />
…
</txp:if_variable>

to this, so you have “if not empty …”:

<txp:if_variable name="myvar" value="" not>
…
</txp:if_variable>

PS: not means “the opposite of the if-expression you give it” (i.e. the else-case)


TXP Builders – finely-crafted code, design and txp

Offline

#38 2026-01-05 23:04:24

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,278
Website Mastodon

Re: link_to_next not working

jakob wrote #342106:


Or version 2, use txp:evaluate to test if a tag inside the container provides any output, e.g.

This is now working as desired!! So many thanks for all your insights.
Now on to the issue of outputting those 6 images along the bottom half!

PS I’ll try your other tips on my earlier code as well.


…. texted postive

Offline

Board footer

Powered by FluxBB