Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-05-27 18:58:38

agovella
Member
From: Houston, TX
Registered: 2005-05-01
Posts: 66
Website Twitter

Have section list page show a single article?

I’m sure this is covered, but my Google-fu won’t pull it up.

Say you have a section: about.

And when someone visits /about, you want the visitor to see a specific article, “about my company” as well as a list of other articles in the about section.

I think the Textpattern question is: How do you show a specific article in the article list context?

Offline

#2 2019-05-27 19:12:25

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

Re: Have section list page show a single article?

Hi,
check the code of our site on github, the particular template, linked to a section, more or less doing what you need. Regarding the list of articles, you could use either the related_articles or the article_custom tags.


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

Offline

#3 2019-05-27 19:58:09

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

Re: Have section list page show a single article?

Another very simple way to front a section with some (introductory) text that you have stored in an article at the top of a section landing page, e.g. in an article list context, is to use a sticky article. An example:

  • Write your About introduction, perhaps with its own heading, in an article and assign it to your about section. Set the status to sticky and then save it.
  • Write your other individual articles in the about section and save as regular live articles assigned to that section.
  • In your page template, you can then do:
<!-- your lead article heading and text -->
<txp:article status="sticky" limit="1">
    <h2><txp:title /></h2>
    <txp:body />
</txp:article>
<!-- the regular article list / individual article view -->
<txp:article />

… which means the normal txp:article tag responds as normal to the article_list context or individual_article context as before, but on a list page, the content of a single sticky article will be shown at the beginning.
txp:article on its own has status="live" as default, so you don’t risk having duplicate content. As the sticky article doesn’t have a permlink in it, it never has its own page and only shows on the section landing page.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2019-05-27 20:09:44

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

Re: Have section list page show a single article?

You can also abuse sections description if 255 chars suffice:

<txp:meta_description type="section" format="" escape="textile" />

Offline

#5 2019-05-29 15:58:13

arellanon
Member
From: San Jose, CA
Registered: 2019-02-26
Posts: 13
Website

Re: Have section list page show a single article?

jakob wrote #318248:

Another very simple way to front a section with some (introductory) text that you have stored in an article at the top of a section landing page, e.g. in an article list context, is to use a sticky article. An example:

  • Write your About introduction, perhaps with its own heading, in an article and assign it to your about section. Set the status to sticky and then save it.
  • Write your other individual articles in the about section and save as regular live articles assigned to that section.
  • In your page template, you can then do:

<!-- your lead article heading and text -->...

… which means the normal txp:article tag responds as normal to the article_list context or individual_article context as before, but on a list page, the content of a single sticky article will be shown at the beginning.
txp:article on its own has status="live" as default, so you don’t risk having duplicate content. As the sticky article doesn’t have a permlink in it, it never has its own page and only shows on the section landing page.

I have never been able to figure out how to keep a certain article at the top of the Home Page. Sticky seems the obvious choice but that does not do it. I tried to figure out the above without luck. I just did a new install and want to get it right the first time. Any help?


Regards, Nick

Offline

#6 2019-05-31 21:36:06

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

Re: Have section list page show a single article?

We should probably add <txp:article status="sticky" /> where appropriate to the default theme, to make it easier for new users: try to replace

                    <txp:if_variable name="front-page">
                        <!-- links by default to form: 'default.txp' unless you specify a different form -->
                        <txp:article limit="5" />

with

                    <txp:if_variable name="front-page">
                        <!-- links by default to form: 'default.txp' unless you specify a different form -->
                        <txp:article status="sticky" />
                        <txp:article limit="5" />

Then sticky articles should be displayed above the live ones.

Offline

#7 2019-05-31 21:53:01

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Have section list page show a single article?

etc wrote #318332:

We should probably add <txp:article status="sticky" /> where appropriate to the default theme

Please raise an issue and I’ll make sure this gets added to the default theme. Thanks!

Offline

#8 2019-05-31 22:22:01

arellanon
Member
From: San Jose, CA
Registered: 2019-02-26
Posts: 13
Website

Re: Have section list page show a single article?

Thank You! That worked. I have another question which is related. I want to but a sticky article at the top of the Home Page, right now I only know how to do that by having a section made for the article. That section ends up being a tag on the nav bar. How can I hide that section from the nav bar and still have the article on the Home Page?


Regards, Nick

Offline

#9 2019-05-31 22:32:25

arellanon
Member
From: San Jose, CA
Registered: 2019-02-26
Posts: 13
Website

Re: Have section list page show a single article?

I appreciate the way you showed how to change the code!

etc wrote #318332:

We should probably add <txp:article status="sticky" /> where appropriate to the default theme, to make it easier for new users: try to replace

<txp:if_variable name="front-page">...

with

<txp:if_variable name="front-page">...

Then sticky articles should be displayed above the live ones.

p.


Regards, Nick

Offline

#10 2019-06-01 12:49:21

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

Re: Have section list page show a single article?

arellanon wrote #318334:

How can I hide that section from the nav bar and still have the article on the Home Page?

You can add exclude="that_section_name" attribute to <txp:section_list /> in body_header misc form, awaiting a more convenient solution.

Offline

#11 2019-06-01 13:20:56

arellanon
Member
From: San Jose, CA
Registered: 2019-02-26
Posts: 13
Website

Re: Have section list page show a single article?

Thank you again. Those were two issues that I always wanted but couldn’t figure out how to do.

Last edited by arellanon (2019-06-01 13:21:13)


Regards, Nick

Offline

Board footer

Powered by FluxBB