Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-08-07 16:10:10

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Article listing, but with the first article featured

On my article listing page, I want to feature the latest article at the top and then list the remaining articles. I initially achieved this using:

  • for the first article: <txp:article limit="1">, and
  • for the listing of subsequent articles: <txp:article offset="1">.

Everything worked well until pagination kicked in. Then what happens is this:

  • results page 1: article 1 featured, articles 2-11 listed,
  • results page 2: article 2 featured, articles 12-21 listed,
  • results page 3: article 3 featured, articles 22-26 listed,
  • results page 4: article 4 featured, no more articles to list, and
  • so on. Yes, this continues until the last article has been the featured one.

What I really want to do is to feature the very latest article on all results pages, with pagination of the remaining continuing as expected.

You can see this in action here >== thesamaras.com/blog

I guess I assumed that <txp:article limit="1"> applied the limit attribute to all articles, rather than just the list currently being acted on.

I know that I can get going with some plugins to identify which page of results I’m on and modify the results accordingly. But before going down that track is there a way to achieve this using core Textpattern functionality?

Offline

#2 2013-08-07 17:37:20

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Article listing, but with the first article featured

I’m a bit rusted but I think you could do:

  • for the featured article on every page: <txp:article_custom section="blog" limit="1" /> (I’m assuming your articles are assigned to a blog section)
  • for the rest (listing of subsequent articles): <txp:article offset="1">.

I think that should be enough. No need to apply any kind of conditional logic.
But if the above doesn’t work, then I think a combination of <txp:variable />, <txp:if_variable> and <txp:page_url /> could do the trick.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2013-08-07 19:13:04

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Article listing, but with the first article featured

maniqui wrote:

I’m a bit rusted but I think you could do:

Yes, that should work. The offset for the pagination is calculated with the formula:

x = offset + pageby(pg - 1)

So, if you set the offset to one, it will skip the first result (the most recent article with the default sorting criteria).

Last edited by Gocom (2013-08-07 19:14:31)

Offline

#4 2013-08-07 21:55:34

aslsw66
Member
From: Canberra, Australia
Registered: 2004-08-04
Posts: 342
Website

Re: Article listing, but with the first article featured

Perfect thank you!

All I had to do was feed article_custom with the current section and it works – that’s because I put my articles into either blog or trips.

Offline

Board footer

Powered by FluxBB