Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-12-29 17:44:27

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Preview slice of next article?

I want to emulate (more or less) a preview slice of the next article as here, at the bottom of the page: Pentagram work page (and all their other Work pages), linked to that next article.

I did something similar—or at least the solution would work—about ten years ago maybe with a tasty smd plugin…

Basically it shows the top so-many-hundred pixels of the next article at the bottom of an article page — click on it and it’ll go to that next article. Note my version may not swish up and appear quite like theirs, so don’t worry about that bit :)

Offline

#2 2021-12-29 20:40:01

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Preview slice of next article?

txp:link_to_next can help you there. It can be used as a container tag to wrap not just “Next page” but also for regular individual article tags. See the first example in the link_to_next docs.

To achieve your affect, you could include the entire next article within the container and simply constrict the display using CSS, e.g. height: 200px; overflow: hidden; and then do the page transition on click.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2021-12-30 11:26:35

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Re: Preview slice of next article?

jakob wrote #332340:

txp:link_to_next can help you there. It can be used as a container tag to wrap not just “Next page” but also for regular individual article tags. See the first example in the link_to_next docs.

To achieve your affect, you could include the entire next article within the container and simply constrict the display using CSS, e.g. height: 200px; overflow: hidden; and then do the page transition on click.

I thank you and hang my head in shame at not having thought of this. I even put in the div and link_to_next wrappers, then brain-farted on what to put in the middle: the output_form for my articles.

<div id="nextarticle">
<txp:link_to_next>
<txp:output_form form="default"/>
</txp:link_to_next>
</div>

Offline

#4 2021-12-30 15:39:54

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Re: Preview slice of next article?

Is it possible to show next articles only from the same section as the current one? My site is a portfolio and I’d like the next thing previewed to be of the same sort of thing as the current one.

Also also, is there a way a specify alternative content is there is no next article?

Last edited by nobi-wan (2021-12-30 16:02:33)

Offline

#5 2021-12-30 16:59:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Preview slice of next article?

nobi-wan wrote #332342:

Is it possible to show next articles only from the same section as the current one?

It should do that automatically. This code from the default template works for me:

<txp:evaluate test="link_to_prev,link_to_next">
    <nav class="paginator" aria-label="<txp:text item="page_nav" />">
        <txp:link_to_prev>
            <txp:text item="prev" />
        </txp:link_to_prev>
        <txp:link_to_next>
            <txp:text item="next" />
        </txp:link_to_next>
    </nav>
</txp:evaluate>

is there a way a specify alternative content is there is no next article?

Sort of but since the link_to_prev/next don’t accept <txp:else /> you might have to fudge it and use a variable, or use individual <txp:evaluate> tags instead of testing for both tags at once as in the above example. e.g. (untested):

<nav class="paginator" aria-label="<txp:text item="page_nav" />">
    <txp:evaluate test="link_to_prev">
        <txp:link_to_prev>
            <txp:text item="prev" />
        </txp:link_to_prev>
    <txp:else />
        <p>Start of list</p>
    </txp:evaluate>
    <txp:evaluate test="link_to_next">
        <txp:link_to_next>
            <txp:text item="next" />
        </txp:link_to_next>
    <txp:else />
        <p>End of list</p>
    </txp:evaluate>
</nav>

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 2021-12-30 17:12:19

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Preview slice of next article?

nobi-wan wrote #332342:

Is it possible to show next articles only from the same section as the current one? My site is a portfolio and I’d like the next thing previewed to be of the same sort of thing as the current one.

Does the context attribute help here? (on second thoughts, probably not). Gotta think about this one … … …

… well, it turns out I made a similar suggestion a while back and it also turns out that there’s a plugin for that: smd_horizon.

Also also, is there a way a specify alternative content is there is no next article?

Yes, you can use txp:evaluate to test if txp:link_to_next produces any output:

<txp:evaluate test="link_to_next">
      <txp:link_to_next form="default" />
   <txp:else />
      … your fallback content here …
   </txp:evaluate>

(BTW: I think you can probably add your form straight to the form attribute of link_to_lext instead of wrapping output_form).

Note: If you end up using smd_horizon – and depending on whether you wrap the existing tags or use the plugin’s own tags – change the test attribute to match the new function, e.g. test="smd_link_to_next".

EDIT II: Stef – mr smd – beat me to it :-)


TXP Builders – finely-crafted code, design and txp

Offline

#7 2021-12-30 19:32:31

nobi-wan
Member
Registered: 2021-02-05
Posts: 23

Re: Preview slice of next article?

Okay, so like a numpty I’d forgotten I hadn’t sectioned my work by section, but by category. It was a while ago. TBH in hindsight I’m not super-bothered about things being out of work-type order because of that — not sure there’s a solution anyway, but now I’ve said that it’s probably an easy one.

I did this:

<txp:evaluate test="link_to_prev">
      <txp:link_to_prev form="default_next" />
   <txp:else />
      <txp:article_custom limit="1" form="default_first" section="portfolio" />
</txp:evaluate>

Where the form default_next is a duplicate of my default but only includes the first image/movie of the article for load lightness, and default_first is a permlink wrapped around the output_form default_next.

(Yes, I switched the running order from next to prev).

For what it’s worth I’ll endeavour to remember to post the page when it’s live.

Thank you Bloke and Jakob! Legends, both.

Last edited by nobi-wan (2021-12-30 19:34:52)

Offline

#8 2021-12-30 22:20:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Preview slice of next article?

If you’re using categories and not sections then jakob is right: try the context attribute which should allow you to keep the category as you jump from article to article.

Alternatively, as mentioned above, smd_horizon should allow you to do it. Note that if you do navigate by sections, the plugin works in reverse to the core tags. The core tags are context-sensitive and will constrain your navigation. smd_horizon can bust out of that mode and navigate across sections.


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

Board footer

Powered by FluxBB