Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-09-26 15:51:43

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Display the latest article from a section with links to other articles

When visting a section I need to display the latest article that was published to it. Underneath I need to display links to the other published articles in this section. I seem to be having a brain freeze regarding this.

Last edited by Algaris (2011-09-26 15:55:33)

Offline

#2 2011-09-26 16:00:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Display the latest article from a section with links to other articles

You can use the attributes limit="1" sort="Posted desc" with txp:article(_custom) to give the first article some special treatment, then offset="1" limit="9" sort="Posted desc" to output the next 9 articles for example. That’s a good way if you want the articles to appear in different places on the page.

Alternatively, if all articles follow each other and the first one needs to be output differently, you could use a single txp:article(_custom) tag and then in your form (or within your container) use txp:if_first_article to output the first article differently from the others, e.g. to show txp:body for the first article and txp:excerpt for the others.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2011-09-26 17:35:17

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Re: Display the latest article from a section with links to other articles

Thanks Jakob. That very nearly does it. The only problem I’m finding is when I output the links to the other articles although the URL is correct it only every displays the last posted article.

—Edit—
Should probably post my code here

*Default page**

<txp:article_custom form="blog" section="blog" sort="Posted desc" />

Blog form

<txp:if_first_article>
<h1><txp:section title="1" /></h1>
<div id="slider2" class="nopad"><txp:images sort="id" category='<txp:custom_field name="slideshow" />' break=""><txp:image /></txp:images></div>
<h2><txp:title /></h2>
<p><txp:body /></p>
<txp:else />
<h2>Previous Entries</h2>
<txp:article_custom form="blog-links" section="blog" offset="1" limit="9999" sort="Posted desc" />
</txp:if_first_article>

Blog Links form
<li><txp:permlink><txp:title /></txp:permlink></li>

Last edited by Algaris (2011-09-26 17:45:00)

Offline

#4 2011-09-26 18:40:08

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: Display the latest article from a section with links to other articles

I would do it like this with limit and offset:

<h1><txp:section title="1" /></h1>
<txp:article_custom section="blog" sort="Posted desc" limit="1" form="blog" />

<h2>Previous Entries</h2>
<txp:article_custom section="blog" sort="Posted desc" offset="1" limit="9999" form="blog-links" />

or like this with if_first_article:

<h1><txp:section title="1" /></h1>
<txp:article_custom section="blog" sort="Posted desc">
  <txp:if_first_article>
    <div id="slider2" class="nopad"><txp:images sort="id" category='<txp:custom_field name="slideshow" />' break=""><txp:image /></txp:images></div>
    <h2><txp:title /></h2>
    <txp:body />
    <h2>Previous Entries</h2>
    <ul>
  <txp:else />
    <li><txp:permlink><txp:title /></txp:permlink></li>
  </txp:if_first_article>
</txp:article_custom>
    </ul>

And if you’re already on the blog section, you should be able to use txp:article and do away with the section attribute.

Last edited by jakob (2011-09-26 18:40:59)


TXP Builders – finely-crafted code, design and txp

Offline

#5 2011-09-27 07:20:42

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Re: Display the latest article from a section with links to other articles

Thank you jakob. I went down the if_first_article route. At first I was having the same problems as before where the links would only display the last posted article. When I change the article_custom to a article tag everything started working as it should.

Offline

#6 2011-09-27 14:06:20

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 581

Re: Display the latest article from a section with links to other articles

I’ve been playing around with this and I was wondering. Is there a way to change this so that it displays a list of all articles in this section after displaying the most recently posted article?

Offline

Board footer

Powered by FluxBB