Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-03-15 17:32:32

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 304
Website

Different number of articles on page 1 and following pages

I have been trying to figure out the following for several days now, but so far no success…

  • On my front (default) page I have two rows of 3 articles each
  • The first “article” is actually not an article, but a design element only visible on the front page
  • So, there are really only 5 articles in total on the front page
  • But on the following pages (after clicking on Older), I would like to have 6 articles
  • I want to do this on the default page
  • Initially, I thought something like if page 1, <txp:article limit="5" />, else <txp:article limit="6" />, but that doesn’t work

For better understanding, here is a dummy page of this design.

Any idea how I can do this?

Last edited by Kjeld (2021-03-15 17:38:32)


JapaneseStreets.com – Japanese street fashion (mostly txp)
Old Photos of Japan – Japan between 1860 and 1940 (100% txp)
MeijiShowa – Stock photos of Japan between 1860 and 1940 (100% txp)

Offline

#2 2021-03-15 19:32:47

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

Re: Different number of articles on page 1 and following pages

Hi Kjeld,

I think you could do that by checking for the pg url parameter. Maybe something like:

<txp:variable name="page" value='<txp:page_url type="pg" />' />
<txp:if_variable name="page" value="">
    <!-- front page -->
    <txp:article limit="5" />
<txp:else />
    <txp:if_variable name="page" value="1">
        <!-- first set of six -->
        <txp:article limit="6" offset="5" />
    <txp:else />
        <!-- subsequent sets of six -->
        <txp:article limit="6" />
    </txp:if_variable>
</txp:if_variable>

I haven’t tried it out but I rather suspect the problem may only shift to the last case and it might skip article #12.

If that is the case, then maybe use the combination of the variable name="page" and txp:evaluate with multiply by six + 5 to determine the right offset variable for each page.

I’m sure Oleg will chip in shortly with a tidier way ;-)


TXP Builders – finely-crafted code, design and txp

Offline

#3 2021-03-15 19:39:52

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

Re: Different number of articles on page 1 and following pages

Another thought: I wonder if you could use a trick for the first page and stick with limit="6". Something like having a dummy article up front that you never show. If you know what article_id it has, you can use:

<txp:if_article_id id="99" not>
    <!-- your form code -->
</txp:if_article_id>

to skip showing it when the first list of six is being shown.

The problem to solve there is to how to keep an article at the front of the sort order. Using time="any" might be an option and a far future date. Or you make a category that the skipped article is assigned to and sort first by that category and then posted desc. A second problem arises, though: you’ll probably want to keep it out of RSS feeds and search etc.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2021-03-15 20:13:07

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: Different number of articles on page 1 and following pages

jakob wrote #329256:

Another thought: I wonder if you could use a trick for the first page and stick with limit="6". Something like having a dummy article up front that you never show.

The problem to solve there is to how to keep an article at the front of the sort order. Using time="any" might be an option and a far future date. Or you make a category that the skipped article is assigned to and sort first by that category and then posted desc. … A second problem arises, though: you’ll probably want to keep it out of RSS feeds and search etc.

Why couldn’t this dummy article be simply sticky? You’d output the articles with

<txp:article status sort="Status DESC, Posted DESC" limit="6" />

and sticky articles are excluded from feeds/search by default, iirc.

Offline

#5 2021-03-15 20:17:52

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: Different number of articles on page 1 and following pages

This said, we can already break lists in variously sized chunks with breakby="5,6,6,..." Probably, pageby could do it too? I remember having thought about it, but something has stopped me… but what?

Offline

#6 2021-03-15 20:28:24

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

Re: Different number of articles on page 1 and following pages

jakob wrote #329255:

I’m sure Oleg will chip in shortly with a tidier way ;-)

What did I say? :-D

etc wrote #329257:

Why couldn’t this dummy article be simply sticky? You’d output the articles with

<txp:article status sort="Status DESC, Posted DESC" limit="6" />...

and sticky articles are excluded from feeds/search by default, iirc.

Nice! So using status on its own without any attribute means “has any status whatsoever”? Or just “live and sticky”?


TXP Builders – finely-crafted code, design and txp

Offline

#7 2021-03-15 20:29:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,263
Website GitHub

Re: Different number of articles on page 1 and following pages

I was going to mention the sticky article approach. But I couldn’t remember if it was sticky only on page 1. If it is, it seems like a winning way to go.


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

#8 2021-03-15 20:32:10

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: Different number of articles on page 1 and following pages

Bloke wrote #329260:

I was going to mention the sticky article approach. But I couldn’t remember if it was sticky only on page 1. If it is, it seems like a winning way to go.

I guess yes, when retrieved with the same <txp:article /> tag that live articles.

Offline

#9 2021-03-15 20:32:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,263
Website GitHub

Re: Different number of articles on page 1 and following pages

jakob wrote #329259:

using status on its own without any attribute means “has any status whatsoever”? Or just “live and sticky”?

It means “publishable” (which is currently live+sticky) but in the status-mods branch, I was investigating being able to extend/expand the status fields. So you could define your own values for whatever purposes and assign them to either ‘published’ or ‘unpublished’ groups. That would (in theory) impact what was output by the <txp:article status> tag.

All theoretical. If only I could get the branch code to work reliably. But it doesn’t. I was about 95% of the way there too, grrr.

Last edited by Bloke (2021-03-15 20:33:58)


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

#10 2021-03-15 20:35:46

etc
Developer
Registered: 2010-11-11
Posts: 4,253
Website GitHub

Re: Different number of articles on page 1 and following pages

jakob wrote #329259:

Nice! So using status on its own without any attribute means “has any status whatsoever”? Or just “live and sticky”?

Just published statuses, I don’t think that even explicit status="3" (for pending articles) would work. Security it is.

Offline

#11 2021-03-15 20:38:46

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

Re: Different number of articles on page 1 and following pages

etc wrote #329257:

Why couldn’t this dummy article be simply sticky? You’d output the articles with

<txp:article status sort="Status DESC, Posted DESC" limit="6" />...

and sticky articles are excluded from feeds/search by default, iirc.

etc wrote #329264:

Just published statuses …

… Excellent, which means …

<txp:article status sort="Status DESC, Posted DESC" limit="6" />

is probably the solution, and your sticky article could also be your “design element” article and so doesn’t even need to be a dummy.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2021-03-16 05:38:18

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 304
Website

Re: Different number of articles on page 1 and following pages

etc wrote #329257:

Why couldn’t this dummy article be simply sticky? You’d output the articles with

<txp:article status sort="Status DESC, Posted DESC" limit="6" />...

and sticky articles are excluded from feeds/search by default, iirc.

This is genius and works perfectly. I could have never come up with this. Thank you so much!

The only drawback I can think of is that there can be only a single sticky article…

Incidentally, I don’t fully understand how sort="Status DESC" makes the sticky article appear first. Does it sort alphabetically (from z down) by the name of the status (Sticky, Live)?


JapaneseStreets.com – Japanese street fashion (mostly txp)
Old Photos of Japan – Japan between 1860 and 1940 (100% txp)
MeijiShowa – Stock photos of Japan between 1860 and 1940 (100% txp)

Offline

Board footer

Powered by FluxBB