Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-03-06 00:51:23
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
<txp:article limit="none" />?
Here’s another “Nice to have, but won’t change the world”.
In <txp:article />
and <txp:article_custom />
the default limit (i.e. no. of articles to generate) is 10. Fair enough, but there are many situations where all articles have to be retrieved.
I know, I know: limit="9999"
is what we all have to do but limit="none"
or limit="0"
would save wear & tear on my number 9 key.
Offline
Re: <txp:article limit="none" />?
Rather, I would suggest removing the limit of 10 articles…
It’s so easily forgotten, numerous times I’ve wondered why a page wouldn’t display all articles, until I realized it was the default limit of 10.
The user doesn’t expect a limit when he hasn’t set that attribute, it’s as simple as that.
More votes? :-)
Kensington TXP powered rock
Offline
#3 2009-04-29 09:42:11
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: <txp:article limit="none" />?
Doesn’t limit="0"
work? It’s already the default value in other list tags, like linklist and comments.
Offline
Re: <txp:article limit="none" />?
I would agree with removing the default “10” limit and setting it to “0” (zero) and “0” would mean unlimited.
Els – as far as the article tags are concerned, “0” does actually mean zero as in no output.
Last edited by thebombsite (2009-04-29 15:32:27)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: <txp:article limit="none" />?
+1 to making the default no limit.
Conceivably there could be a preference setting, but I don’t see the need.
Code is topiary
Offline
#6 2009-04-29 17:44:36
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: <txp:article limit="none" />?
thebombsite wrote:
Els – as far as the article tags are concerned, “0” does actually mean zero as in no output.
Yeah, I just noticed that. Is there a reason for this inconsistent behaviour? <txp:article limit="0" />
displays zero articles, <txp:linklist limit="0" />
displays all links…
Offline
Re: <txp:article limit="none" />?
Els wrote:
Is there a reason for this inconsistent behaviour?
Hmmmm. linklist
(and other similar tags) check to see if there is a limit set before applying SQL’s LIMIT clause. article
(and by inference article_custom
) do not check if limit
contains a non-zero value, thus always apply the SQL LIMIT.
It does seem a tad backwards. If you’ve gone to all the trouble of specifying a zero limit which you know will return no articles, why bother putting an article tag at all?! The only possible reason I could think for its inclusion would be to simulate pgonly
, but whether that’s useful is questionable.
I’d be tempted to keep the default limit="10"
but I’m with Adi and would prefer limit="0"
mean “no limit”, unless there’s a very good reason for it being the way it is currently.
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 2009-04-29 21:30:07
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: <txp:article limit="none" />?
Bloke wrote:
The only possible reason I could think for its inclusion would be to simulate
pgonly
, but whether that’s useful is questionable.
The only possible use would be to stop Txp complaining that you don’t have an article tag in your template (but we have pgonly for that). For other situations where pgonly is used, like displaying the search results count, it’s totally useless.
Offline
Re: <txp:article limit="none" />?
Bloke wrote:
If you’ve gone to all the trouble of specifying a zero limit which you know will return no articles, why bother putting an article tag at all?! The only possible reason I could think for its inclusion would be to simulate
pgonly
, but whether that’s useful is questionable.
Or if you are trying to do some black tags-in-tags magic… and 0 could be one of the possible values.
<txp:article limit='<txp:variable name="theCounter" />' />
(Of course, in that case you can also play with txp:if_variable
conditionals to not output txp:article
if variable = 0.)
Last edited by maniqui (2009-04-29 21:33:42)
Offline
Re: <txp:article limit="none" />?
Totally forgot about this.
Making article / article_custom accept limit="0"
to mean all rows is actually a fairly easy change — just 2 lines to alter. But there’s one potential pitfall: if you specify a zero limit, any offset
is ignored and your results always start from the first row.
Is this a problem? Can anyone think of any real-world reasons for wanting to list all rows in an article or article_custom tag and skip the first N rows — bearing in mind that paging will be disabled when limit="0"
? If so then we need to work around it or leave the behaviour as it is now. For a workaround, MySQL is horrible in this regard; from the manual:
To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:
SELECT * FROM tbl LIMIT 95,18446744073709551615;
So to do this we’d have to choose a ridiculously large number and use it as the second parameter to MySQL’s LIMIT. Using such magic numbers makes me nervous.
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
#11 2010-07-20 08:36:10
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: <txp:article limit="none" />?
Bloke wrote:
Is this a problem? Can anyone think of any real-world reasons for wanting to list all rows in an article or article_custom tag and skip the first N rows — bearing in mind that paging will be disabled when
limit="0"
?
Could be – you wouldn’t want to prevent a scenario such as:
- show first three articles in “featured”/full monty” mode
- list articles #4 through to the end in “archive”/“click to read mode”
If there’s only, say 20-odd articles who cares about paging?
Offline
Re: <txp:article limit="none" />?
gomedia wrote:
Could be – you wouldn’t want to prevent a scenario such as <snip>
In which case, how’s best to proceed? I really don’t like choosing a large number and chucking it in the mix. If we choose a million, someone somewhere will have a million articles (yeah, ok, it’d take a week to render to the page with limit="0"
but hey!)
For reference, here’s the current diff without offset:
Index: textpattern/publish.php
===================================================================
--- textpattern/publish.php (revision 3376)
+++ textpattern/publish.php (working copy)
@@ -778,7 +778,7 @@
$search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
//do not paginate if we are on a custom list
- if (!$iscustom and !$issticky)
+ if (!$iscustom and !$issticky && $limit)
{
$grand_total = safe_count('textpattern',$where);
$total = $grand_total - $offset;
@@ -804,7 +804,7 @@
}
$rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod".$match, 'textpattern',
- $where.' order by '.doSlash($sort).' limit '.intval($pgoffset).', '.intval($limit));
+ $where.' order by '.doSlash($sort).(($limit) ? ' limit '.intval($pgoffset).', '.intval($limit) : ''));
// get the form name
if ($q and !$iscustom and !$issticky)
$fname = ($searchform ? $searchform : 'search_results');
And here’s how it might look if we chose to allow offset + limit=“0”:
Index: textpattern/publish.php
===================================================================
--- textpattern/publish.php (revision 3376)
+++ textpattern/publish.php (working copy)
@@ -778,7 +778,7 @@
$search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
//do not paginate if we are on a custom list
- if (!$iscustom and !$issticky)
+ if (!$iscustom and !$issticky && $limit)
{
$grand_total = safe_count('textpattern',$where);
$total = $grand_total - $offset;
@@ -804,7 +804,7 @@
}
$rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod".$match, 'textpattern',
- $where.' order by '.doSlash($sort).' limit '.intval($pgoffset).', '.intval($limit));
+ $where.' order by '.doSlash($sort).(($limit) ? ' limit '.intval($pgoffset).', '.intval($limit) : (($pgoffset) ? ' limit '.intval($pgoffset).', 999999999' : '') ));
// get the form name
if ($q and !$iscustom and !$issticky)
$fname = ($searchform ? $searchform : 'search_results');
999999999? Yuck. Even if we make it a constant in constants.php it still smells of pork products to me. There has to be a better way.
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