Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2020-07-23 16:31:00

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Navigating back to section from article #2

Have you tried checking for <txp:link_to_prev /> inside the first <txp:link_to_prev /> tag?

Offline

#14 2020-07-23 16:44:32

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

Re: Navigating back to section from article #2

etc wrote #324819:

Have you tried checking for <txp:link_to_prev /> inside the first <txp:link_to_prev /> tag?

Ummm, no. How does that help beyond how <txp:evaluate> does right now? This is the rather (convoluted, but it works) method I’ve come up with:

<nav class="paginator" aria-label="<txp:text item="page_nav" />">
   <txp:evaluate test="link_to_prev">
      <txp:link_to_prev>
         &laquo; <txp:title />
      </txp:link_to_prev>
   <txp:else />
      <txp:if_individual_article>
         <a href="/<txp:section />" rel="prev">&laquo; <txp:section title /></a>
      </txp:if_individual_article>
   </txp:evaluate>
   <txp:evaluate test="link_to_next">
      <txp:link_to_next>
         <txp:title /> &raquo;
      </txp:link_to_next>
   <txp:else />
      <txp:if_article_list>
         <txp:article limit="1" sort="Posted asc"><a href="<txp:permlink />" rel="next"><txp:title /> &raquo;</a></txp:article>
      </txp:if_article_list>
   </txp:evaluate>
</nav>

The reason for the if_article_list and if_individual_article dance is because this same navigation could apply in either situation – if on a landing page or on an individual article.

If I’m on a landing page, there is no previous article by design so the code above would dutifully make me a link to the same section I’m looking at if we don’t do the check.

Same on the last article. If we didn’t check if the visitor is viewing the landing page, the link would get generated to the same last article when you were viewing the last article in the section.

Anyway, that works. Improvements welcome.


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

#15 2020-07-23 16:59:08

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Navigating back to section from article #2

Sorry, I meant this:

What I think I want to do is tweak the inter-article navigation above so it somehow knows that we’re on the 2nd article in the section (or that there’s only one article “to the left” of this one) and generate a link to the /section landing page in this case, instead of to the first article permlink.

<txp:link_to_prev>
    <txp:variable name="link_to_prev_prev" value='<txp:link_to_prev />' />
</txp:link_to_prev>

<txp:if_variable name="link_to_prev_prev" value>
    the previous article is not the first one
<txp:else />
    <txp:if_variable name="link_to_prev_prev">
        the previous article is the first one
    </txp:if_variable>
</txp:if_variable>

Offline

#16 2020-07-24 01:54:01

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

Re: Navigating back to section from article #2

If your example is the real one, the About section, may not need links to next/previous which are only relevant, in my view, for blogs. Sections such the about one have a finite number of pages, 1, 2, 5, 10, 15, whatever, which can be all linked to from a secondary navigation.


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

Offline

#17 2020-07-24 08:32:16

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

Re: Navigating back to section from article #2

colak wrote #324822:

the About section, may not need links to next/previous which are only relevant, in my view, for blogs.

True. It’s just a nicety to have links at the bottom of the article. So when you’ve finished reading you don’t have to track up to the nav to find other resources in this section that may be of interest. If you land on Meet The Team from a search engine and read it, you can see ‘oooh, why choose us?’ and click immediately to find out why.

Plus, it saves using if_conditionals in the page template and/or making a new template for ‘small content’ 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