Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-05-10 18:37:25

agovella
Member
Registered: 2005-05-01
Posts: 39

How do you create landing pages for Sections and their Categories?

Ok… so like many, I go several years between Txp coding, so I may have forgotten something really obvious, but….

Sections

I have a Home page that links to Sections at /section/.

For each Section, I want to display a single Article (as a landing page) at the Section’s path, /section/.

Categories

In addition, each Section has several associated Categories accessed beneath that Section at /section/category/.

For each Category, I want to display a single Article (as a landing page) at the Category’s path, /section/category/.

Articles

In each category, there may be associated Articles displayed at the /section/category/title.

My problem

I have something working:

For Sections, I use sticky articles with no category to surface a single article on the Section landing page. (/section/title is also accessible, but no content displays, and only the TxP admin links there.)

For Categories, I display the oldest article in that category which, by process/luck, is always the Category landing content. Permalink links all category articles to /section/category/title, including the Category landing page. I would like the Category landing page to only ever show up at /section/category/

Here’s my code in the Page:


<txp:if_individual_article>
    <txp:article form="article-pxd" />
</txp:if_individual_article>

<txp:if_article_list>
    <txp:if_category>
        <txp:article form="article-pxd" limit="1" sort="Posted asc" />
    <txp:else />
        <txp:if_section>
            <txp:article form="section-article-pxd" limit="1" sort="posted asc" status="sticky" />
        </txp:if_section>
    </txp:if_category>
</txp:if_article_list>

(You’ll notice I removed search results to make it easier for me to work through.) Am I missing something basic?

The only think I can think of is to move the Section and Category landing content articles to a special, hidden Section, and specifically display them on the appropriate page with article_custom with an ID attribute. (And provide no other links to them.) But that seems like too much of a maintenance headache.

Last edited by agovella (2020-05-10 18:41:57)

Offline

#2 2020-05-10 20:56:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: How do you create landing pages for Sections and their Categories?

How much content is in each category landing article? Is it a lot? If not and it’s only a short description of the category, you can use the category Description field (Section has them too) and the use the meta_description tag to output them. See Example 3 in the tag doc page.

That means you don’t need a spare sticky article floating around, and makes the page logic simpler.


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

#3 2020-05-11 06:29:27

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 7,905
Website

Re: How do you create landing pages for Sections and their Categories?

Check my response here as it may provide you with some hints.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#4 2020-05-11 19:03:56

agovella
Member
Registered: 2005-05-01
Posts: 39

Re: How do you create landing pages for Sections and their Categories?

@bloke, it’s a full article, so description won’t quite work. (I tried it, though…)

Examples from my site:

@colak, sounds like your ultimate solution was to use a custom field to include the landing page article where needed and to exclude it from article lists for that category? Is that accurate?

Offline

#5 2020-05-11 21:23:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: How do you create landing pages for Sections and their Categories?

Another option then, based around yours: how about a hidden section (I often use ‘snippets’) that operates as below:

  1. In Txp 4.8, create your section called ‘snippets’ and assign it no page or stylesheet from your theme. That effectively makes it pageless, i.e. it can’t appear anywhere in your site unless you explicitly call it, and people can’t discover the URL, since it doesn’t have one.
  2. Create articles in that section with names that reflect which category it represents (for your own sanity so they’re easy to find).
  3. Assign each snippet article with its corresponding category in category1. This is so you can filter by it.
  4. In your page template, use <txp:article_custom section="snippets" category='<txp:category />' form="article-pxd" limit="1" /> to pull out any article matching the category from the hidden section when you’re filtering by that category on your landing page.

It’d be nice if you could extract the article by its name instead of having to assign the category as well to it. Sadly, the filters don’t work by name. But as long as you assign the category to the article, you create a link that you can exploit.

For bonus points, if you don’t want the snippet articles always cluttering up your Content->Articles list, you can hide them with a simple few-line plugin to all but Publisher accounts. Or you could offer a checkbox toggle at the top of the list to switch between showing and hiding articles in the snippets section. I have examples of both types of plugin if you’re interested.

How’s that?

Last edited by Bloke (2020-05-11 21:32:43)


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 2020-05-11 22:14:18

agovella
Member
Registered: 2005-05-01
Posts: 39

Re: How do you create landing pages for Sections and their Categories?

@bloke, That’s genius.

And it keeps me from needing a custom field, so I keep my install “cleaner”.

That’s awesome. Thanks!

I feel like this should go in some kind of cookbook.

Offline

#7 2020-05-11 22:36:43

etc
Developer
Registered: 2010-11-11
Posts: 3,651
Website

Re: How do you create landing pages for Sections and their Categories?

Why wouldn’t you use sticky articles for Categories too? In 4.8 you can filter them out on Section landing pages with something like

<txp:article_custom status="sticky" section category exclude="category" />

Offline

#8 2020-05-11 22:40:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: How do you create landing pages for Sections and their Categories?

Ha, and like that *pooooof* the real genius is revealed. Oleg, that is far far better than my convoluted offering. Totally forgot about article_custom’s newfound exclusion powers.


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-05-12 13:36:14

etc
Developer
Registered: 2010-11-11
Posts: 3,651
Website

Re: How do you create landing pages for Sections and their Categories?

Bloke wrote #322925:

Oleg, that is far far better than my convoluted offering.

I’d say they are complementary: yours is for section-agnostic categories and mine is for section+category combo.

Bloke wrote #322920:

It’d be nice if you could extract the article by its name instead of having to assign the category as well to it. Sadly, the filters don’t work by name.

It’s in our power to add some title attribute to <txp:article />. Though, I’d rather match it against url_title than Title.

Offline

#10 2020-05-12 13:57:02

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,328
Website

Re: How do you create landing pages for Sections and their Categories?

etc wrote #322940:

It’s in our power to add some title attribute to <txp:article />. Though, I’d rather match it against url_title than Title.

Me too. That’s what I meant by matching title, sorry for not being clear. Matching against an article’s real title is not practical!

Matching using the title attribute could be confusing, though, since every other use of it throughout the tag suite returns the human readable title. So if we were to do this, I’d vote for a url_title attribute. The clarity afforded is more beneficial than the extra 4 characters required.

Last edited by Bloke (2020-05-12 13:58:44)


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