Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-05-14 10:06:44

NickML
Member
From: Scotland
Registered: 2006-05-14
Posts: 58
Website

Problems with Section listings and pageby affecting Older and Newer

First post – hope I’ve posted in the right place. I’ve already searched the archives and the FAQs.

I’ve run into a problem while splitting Section lists with offset and pageby. I’ve designed my site so that goingto www.mysite.com/Sectiontitle would get a dated decsending list of articles in that section with excerpt. However, this morning I changed the code to split the results to include adverts so the results look like:
article – article – advert – article – article – advert – article – article. This in itself works fine – but the Older and Newer tags seem to be affected by the change.

I think the problem is that if there is now a full complement of six articles to show on the next “Section listings” page, “Older” doesn’t show. (By Older I mean the tag <code><txp:older>Older articles</txp:older></code>) Which sounds confusing, so I’ll explain it this way:

  • If there are between one and five articles in total in the section, they all show on the first page, and Older doesn’t show (correct)
  • If there are six articles in total in the section, six show on the first page, and Older doesn’t show (correct)
  • If there are between seven and eleven articles in total in the section, six show on the first page, and Older doesn’t show (incorrect)
  • If there are twelve articles in total in the section, six show on the first page, and Older shows (correct). On the second page, six articles show, and Older doesn’t show on the second page (correct)
  • If there are between thirteen and seventeen articles in total in the section, six show on the first page, and Older shows. On the second page, six articles show and Older doesn’t show (incorrect)

Here is the relevant code for the section:

<code>

<txp:if_article_list>

<div class=“indexcolumn”>

<div class=“bigheadline”><txp:section title=“1” /></div>

<div class=“body”> List of current articles in our <txp:section title=“1” /> archives:</div>

<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“2” pageby=“6” />

<!— GOOGLE AD CODE GOES HERE>

<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“2” offset=“2” pageby=“6” />

<!— GOOGLE AD CODE GOES HERE>

<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“2” offset=“4” pageby=“6” />

<div id=“Layer1” style=“position: absolute; left: 0px; width: 250px; height: 18px; z-index: 1”><div class=“navigation”><txp:newer>Newer articles</txp:newer></div></div>
<div id=“Layer2” style=“position: absolute; left: 250px; width: 250px; height: 18px; z-index: 2”><div class=“navigation” align=“right”><txp:older>Older articles</txp:older></div></div>

</txp:if_article_list>
</code>

Any ideas ? Any help is much appreciated.

Nick

Last edited by NickML (2006-05-14 10:15:25)

Offline

#2 2006-05-14 11:08:00

NickML
Member
From: Scotland
Registered: 2006-05-14
Posts: 58
Website

Re: Problems with Section listings and pageby affecting Older and Newer

Looking into this a little further, it seems the problems I am experiencing with Older and Newer seems to be deeper than I first thought:

Example: I have a section called “News” with 14 articles.

  • mysite.com/News shows the first six results correctly, with the Older tag correctly pointing to the next set of articles in that section.
  • mysite.com/News/?pg=2shows the next six results correctly, with the Older tag incorrectly missing.
  • Forcing the next set of results by entering “mysite.com/News/?pg=3” directly into the browser, shows the final two results. Newer tag points correctly at “/News/?pg=2”, but the Older tag points at “/News/?pg=4”, which doesn’t contain any results.

~Nick

Last edited by NickML (2006-05-14 11:52:05)

Offline

#3 2006-05-14 15:24:33

NickML
Member
From: Scotland
Registered: 2006-05-14
Posts: 58
Website

Re: Problems with Section listings and pageby affecting Older and Newer

Not a solution as such, but a workaround. Replacing:

<code>
<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“2” pageby=“6” />
<!— GOOGLE AD CODE GOES HERE —>
<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“2” offset=“2” pageby=“6” />
<!— GOOGLE AD CODE GOES HERE —>
<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“2” offset=“4” pageby=“6” />
</code>

with:

<code>
<!— GOOGLE AD CODE GOES HERE —>
<txp:article sortby=“Posted” sortdir=“desc” form=“article_index_1” limit=“6” />
<!— GOOGLE AD CODE GOES HERE —>
</code>

solves the problem. Not quite what I wanted, but it’ll do for now. Any ideas as to what was wrong with the first bit of code are still very much appreciated, though…

~ Nick

Offline

#4 2006-05-27 18:23:08

fh
New Member
Registered: 2006-05-27
Posts: 3

Re: Problems with Section listings and pageby affecting Older and Newer

I have experienced the problem as well. Seems that pageby does not work correctly with Older and Newer, I will delve deeper into the code and see what’s wrong.

Offline

#5 2006-05-27 19:02:26

fh
New Member
Registered: 2006-05-27
Posts: 3

Re: Problems with Section listings and pageby affecting Older and Newer

okay… I got it.

in publish.php under the function doArticles numPages is calculated as follows:

$numPages = ceil($total/$pageby);

However, $total is calculated this way:

$total = safe_count('textpattern',$where) - $offset;

If doArticles is called more than once in a page using $offset values, then numPage will be incorrect anywhere after the second articles tag (i.e. offset > 0). Or you can modify the code to the following:

$numPages = ceil(($total+$offset)/$pageby);

Which works perfectly in your code.

Offline

#6 2006-05-27 20:59:46

NickML
Member
From: Scotland
Registered: 2006-05-14
Posts: 58
Website

Re: Problems with Section listings and pageby affecting Older and Newer

Good catch – thanks for the solution.

~ Nick

Offline

#7 2006-05-27 22:50:51

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Problems with Section listings and pageby affecting Older and Newer

Does this work correctly with a single article tag?

<txp:article offset=2 limit=10 />

I suspect not. (12 articles: first page shows articles 3-12, $total is 10, $numpages = ceil((10+2)/10) = 2, but it should be 1)

Last edited by zem (2006-05-27 22:55:55)


Alex

Offline

Board footer

Powered by FluxBB