Page Count

Posted by ErichSteinboeck on 28 Mar 2009 09:55, last edited by GoVegan on 24 Mar 2013 13:05

Tags: count javascript listpages pages

rating: +14+x

CountPages module

Beginning August 7th, 2009, the instructions contained on this page are no longer recommended, and simply will not work for sites with more than 250 pages due to a pagination limit imposed by Wikidot to reduce server stress.

As a much better alternative, a new module has been created specifically for the task of counting pages! It is the CountPages module!

This new module works in a similar way to ListPages but only has one variable available — %%count%%.

Click here to read more!

Did you ever wish to count the number of pages in a category? Or count all pages of your wiki?

Find out how you can do it.

Step by Step

Step 1

Create a page inc:page-count-prepend with the following code.

Note:

  • Replace community (first line of code) with the name of your Wiki
  • Otherwise copy/paste the code exactly as-is, don't remove or change anything
[[embed]]<iframe src="http://community.wdfiles.com/local--code/inc:page-count-prepend/1#\
[!--">
[[code type="html"]]
<html>
 <head><title>Page Count</title>
  <style type="text/css">
   @import url("http://www.wikidot.com/common--theme/base/css/style.css");
  </style>
 </head>
 <body>
  <script type="text/javascript">
 
   // (…#) XXXXX... # prepend # append (#…)
   var params = /^[^#]*#([^#]*)#?([^#]*)#?([^#]*)#?.*$/;
 
   var match = params.exec(unescape(window.location.href)); // #'s may be escaped
   if (match) {
    var prepend = '';
    var append = '';
 
    if (match[2] && match[2] != '{$prepend}')
     prepend = match[2] + ' ';
    if (match[3] && match[3] != '{$append}')
     append = ' ' + match[3];
 
    document.write(prepend + match[1].length + append);
   }
   else
    document.write('<i>(none)</i>');
  </script>
  <noscript>
   <i>(cannot count)</i>
  </noscript>
 </body>
</html>
[[/code]]
--]

Step 2

Create a page include:page-count-append with the following code.

Note: Copy/paste the code exactly as-is, don't remove or change anything

#{$prepend}#{$append}" frameborder="0" scrolling="no" width="100%" height="18px"></iframe>[[/embed]]

Step 3

Use the following code on your page where you want to show a count of pages.

[[module ListPages criteria separate="no" perPage="10000" prependLine="[[include inc:page-count-prepend]]" appendLine="[[include inc:page-count-append prepend=leading-text | append=trailing-text]]"]]
X[[/module]]


where
  • criteria is any ListPages selection criteria, like category="howto"

  • leading-text is any text that should be shown immediately in front of the the number of pages. It may include HTML (no Wikidot) tags, e. g. “Category <em>howto</em>:”. prepend=leading-text is optional.
    • If you want to include a double quote (“"”) it must be escaped as “%22”.
    • “#” cannot be used within leading-text, neither as-is, nor in its escaped form “%23”
    • currently Cyrillic text doesn't work in Firefox or Safari; works in Opera though
    • If you'd like to add a link to leading-text (as discussed before, if would have to be an HTML <a href="…">…</a> and not a Wikidot [[[…|…]]] tag) it will only work in the scope of the displayed page if you add target=_parent to the <a ... tag. Find an example for this below.

  • trailing-text is any text that should be shown immediately after the number of pages. As above it may include HTML and any double quotes must be escaped as “%22”. The above notes about double quotes, “#” and adding links applies here too. append=trailing-text is optional.

Examples

What you type … What you get …

[[module ListPages category="howto" separate="no" limit="250" perPage="250"
prependLine="[[include inc:page-count-prepend]]"
appendLine="[[include inc:page-count-append prepend=Pages in category <em>howto</em>:]]"]]
X[[/module]]

Sorry, no match for the embedded content.

[[module ListPages category="*" separate="no" limit="250" perPage="250"
prependLine="[[include inc:page-count-prepend]]"
appendLine="[[include inc:page-count-append prepend=<strong>Community pages: | append=in total</strong>]]"]]
X[[/module]]

Sorry, no match for the embedded content.

[[module ListPages category="*" separate="no" limit="250" perPage="250"
prependLine="[[include inc:page-count-prepend]]"
appendLine="[[include inc:page-count-append prepend=Community <a href=%22http://community.wikidot.com/system:pagecalendar%22 target=%22_parent%22>pages</a>: | append=in total]]"]]
X[[/module]]

Limitations

Wrong totals

As this page count code depends on module ListPages, and ListPages currently does not list any pages starting with underscore (e. g. _template or howto:_style), the displayed totals are off by the number of these pages in the ListPages selection.

On 5. August 2009 the ListPages Module was changed for performance reasons:
If you use the Page count on a site with more than 250 pages over a given category ( or over all) - than you will get pagination!

Browser support

The JavaScript-based solution described here may not be supported by all browsers.

Although this JavaScript-based solution tries to degrade as gracefully as possible if a browser doesn't support or has disabled JavaScript, the best it can do is display “(cannot count)” instead of displaying the actual count.

Please post your browser name and version if you are successfully using it or if you find that it doesn't work.

Browsers successfully tested: Firefox 2 & 3, Google Chrome, Internet Explorer 6 & 7, Opera 9.6, Safari 3 & 4
Browsers that do not work: None reported yet, but any browsers without JavaScript (e. g. Lynx) or browsers with deactivated JavaScript will not work

Backlinks

Author

ErichSteinboeckErichSteinboeck. Please visit his/her userPage.


Related articles

Comments

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.