Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-23 14:53:18

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

Navigating back to section from article #2

This might be a strange one. But I have a menu system:

  • About us (section /about-us)
    • Meet the team (article /about-us/meet-the-team)
    • Why choose us (article /about-us/why-choose-us)
  • Products (section /products)
    • Product 1 (article /products/product-1)
    • Product 2 (article /products/product-2)

The navigation bar only lists the top level nav items (About us, Products etc) and when you click one of those this happens:

  1. The first article (by Posted date) is displayed in its entirety as “landing page content”. In the case of ‘About us’, this is an article called ‘A true partnership’.
  2. A secondary nav appears with the article titles in it excluding the first article posted (offset="1"). This allows you to get to the remainder of the articles in the section.

I may add a dropdown nav so as you hover/tap a main nav item, its sub-menu articles are revealed, but I’m not sure yet.

Anyway, that’s not strictly the issue. The issue is with inter-article navigation. With the traditional next/prev nav structure:

<txp:evaluate test="link_to_prev, link_to_next">
    <nav class="paginator" aria-label="<txp:text item="page_nav" />">
        <txp:link_to_prev>
            &laquo; <txp:title />
        </txp:link_to_prev>
        <txp:link_to_next>
            <txp:title /> &raquo;
        </txp:link_to_next>
    </nav>
</txp:evaluate>

When you’re viewing, say, Meet The Team (the 2nd article in the section), the above nav code adds a ‘prev’ permlink pointing to the first article (which is actually the landing page content) but as ‘about-us/a-true-partnership’. There is therefore duplicate content:

  • /about-us
  • /about-us/a-true-partnership

And:

  • /products
  • /products/award-winning-products

etc.

I don’t particularly want to use redirects here to bounce to the individual article when you hit the bare /section URL (although that’s a last resort) because it’s a site management overhead.

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.

Can anyone think of a Txp tagish way to achieve this?


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

#2 2020-07-23 15:06:11

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

Re: Navigating back to section from article #2

How about making the first landing-page article a sticky article?

I’m pretty sure that takes it out of the inter-page navigation and you don’t need to fuss with offset="1". It also avoids the duplication of /about-us/ and /about-us/a-true-partnership.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2020-07-23 15:16:35

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

Re: Navigating back to section from article #2

jakob wrote #324808:

How about making the first landing-page article a sticky article?

A fine idea except that I’m already using sticky articles for “banners” (notices) that can be turned on and off per section.

Unless there’s a way to distinguish between sticky ‘types’ in the nav? Maybe by putting banners in a dedicated category so I can have up to 2 stickies per article:

  1. The (always present) ‘regular’ uncategorized landing page article; and
  2. The (optional) banner in, say, a ‘banner’ category (or with ‘banner’ as its parent, because category1 indicates the ‘severity’ of the banner notice: red, amber, blue).

Is that doable do you think?


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 2020-07-23 15:21:24

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

Re: Navigating back to section from article #2

I knew there had to be a reason why you hadn’t done that already ;-)

What about turning the concept around:

  • use the sticky articles for the landing pages (i.e. the traditional way)
  • put the banners in a pageless section and name them by section name or a matching category name etc. so they are only displayed if a matching article exists or is live.

TXP Builders – finely-crafted code, design and txp

Offline

#5 2020-07-23 15:24:25

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

Re: Navigating back to section from article #2

Or you add a banner category to the sticky article and use a form for displaying the regular sticky article that skips displaying any article with a “banner” category assigned.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2020-07-23 15:40:25

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

Re: Navigating back to section from article #2

Putting the banners in a pageless section has merit. I already have the “home page banner” in a pageless section by virtue of the fact it has to live somewhere and has to have a section. So putting all the banners in that section does win from a standardisation perspective.

From a site management perspective, using the article title as the section to match does mean the banner can’t have a title, as such, unless it’s put in the body. I do have a Subheading custom field #1 so I suppose I could use that as the title (or use that as the corresponding section) but both seem like a bastardisation and need documenting.

I might just do that. It’s probably simpler than figuring out how to do parent category matching. Best I can do is something like this:

<!-- banner -->
<txp:article_custom status="sticky" section='<txp:section />' category="critical, notice, information" form="announcement" />
<!-- landing page -->
<txp:article status="sticky" category="critical, notice, information" exclude="category" form="article-single" limit="1" sort="Posted asc" />

But that doesn’t work. Maybe I have to use article_custom for both?

(by “doesn’t work” I of course mean, it does work IF the banner article is newer than the other sticky. If the order is swapped, the banner is output twice, so the category/exclude doesn’t appear to be doing what I think).

Last edited by Bloke (2020-07-23 15:44:39)


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

#7 2020-07-23 15:47:20

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

Re: Navigating back to section from article #2

I agree, there may be a good reason for putting the banner for a section in the same section.

Bloke wrote #324812:

From a site management perspective, using the article title as the section to match does mean the banner can’t have a title, as such, unless it’s put in the body.

You could make the article_url_title match the section but leave the title as is. It does require you to instruct the user to manually modify that to match the section and that is an extra step and a potential point of failure.

figuring out how to do parent category matching. Best I can do is something like this:

Is there any reason why you can’t assign the banners to “banner” in category1 and “banner-status” in category-2. Then you just need to match against “banner” and don’t need to worry about the parent aspect.

Alternatively output all the sticky articles and use if_article_category … not in the form you use to skip any banner articles.


TXP Builders – finely-crafted code, design and txp

Offline

#8 2020-07-23 15:56:17

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

Re: Navigating back to section from article #2

jakob wrote #324813:

You could make the article_url_title match the section but leave the title as is. It does require you to instruct the user to manually modify that. It is an extra step and point of potential failure.

That has merit, despite the documentation aspect. If I can’t code my way out of this, then that might work.

Is there any reason why you can’t assign the banners to “banner” in category1 and “banner-status” in category-2.

I could. Just seemed redundant to use both. By virtue of stating that the sticky article is one of the banner alert-level types implies it’s a banner already. I’d like to do: <txp:article_custom parent="alert-level" /> or something clever with exclude.

Hmm, actually, maybe I’m using it wrong. Maybe I need exclude="alert-level" and that’ll not consider anything with that parent. I’ll try that. Otherwise…

EDIT: <txp:article status="sticky" category="critical, notice, information" exclude="alert-level" form="article-single" limit="1" sort="Posted asc" /> doesn’t behave as I expect so presumably exclude can’t be used this way. Which makes kind of sense: I mean, how does it know I’m talking about categories to exclude?

output all the sticky articles and use if_article_category … not in the form you use to skip any banner articles.

… this might be the (relatively expensive) workaround.

Last edited by Bloke (2020-07-23 16:03:10)


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

#9 2020-07-23 16:08:48

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

Re: Navigating back to section from article #2

Bloke wrote #324814:

… this might be the (relatively expensive) workaround.

Is it that expensive? Surely it’s still one db query for several sticky articles so the “expense” is no more than one iteration of the loop until the relevant article is reached. The order of the articles would be irrelevant.

If you really need to cut down on queries, you could output all sticky articles up front and assign the respective output to variables you then output further down the page. Not as elegant code-wise but might save you one query.


TXP Builders – finely-crafted code, design and txp

Offline

#10 2020-07-23 16:13:16

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

Re: Navigating back to section from article #2

jakob wrote #324815:

Is it that expensive?

I was actually thinking ‘expensive’ because I couldn’t use the form attribute and would have to duplicate my form code in the article container to do the conditional (since I’m using article-single elsewhere for regular article content and don’t want to taint it with conditional stuff that’s only relevant for this case – it’s basically my ‘default’ Form that I need to one day migrate back to).

But this works:

<!-- banner -->
<txp:article_custom status="sticky" section='<txp:section />' category="critical, notice, information" form="announcement" limit="1" />
<!-- regular sticky article -->
<txp:article status="sticky" sort="Posted asc">
   <txp:if_article_category not name="critical, notice, information">
      <txp:output_form form="article-single" />
   </txp:if_article_category>
</txp:article>

Thank you for your help with figuring this out. I’ll go with this for the time being unless some better tag-fu crops up.

Last edited by Bloke (2020-07-23 16:14:34)


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

#11 2020-07-23 16:17:40

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

Re: Navigating back to section from article #2

Cool! The output_form idea works well there :-)


TXP Builders – finely-crafted code, design and txp

Offline

#12 2020-07-23 16:18:59

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

Re: Navigating back to section from article #2

The saga continues: that doesn’t directly solve the original issue, though. While I now get no link to previous (first) article I actually want a link to the landing page in this case.

But at least now I have situation I can test more easily: the non-existence of a “previous” article is the same as “only stickies to the left”. So a swift bit of conditional testing around that eventuality should allow me to manually construct a link to the current section if there’s no ‘prev’ :)

Last edited by Bloke (2020-07-23 16:20:09)


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