Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#2 2009-04-29 00:24:03

jan
Member
From: Utrecht, The Netherlands
Registered: 2006-08-31
Posts: 71
Website

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

#4 2009-04-29 15:28:38

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

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

#5 2009-04-29 17:06:34

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#7 2009-04-29 21:20:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

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

Online

#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

#9 2009-04-29 21:33:11

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

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)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#10 2010-07-20 08:29:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

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

Online

#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

#12 2010-07-20 09:00:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

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

Online

Board footer

Powered by FluxBB