To use drupal.org as an example, when I go to recent posts and click on the pager to go to page 2 of the results,

«first ‹previous 1 2 3 4 5 6 next› last»

The URL for page 2 is
http://drupal.org/tracker?page=1

When it seems like it should be
http://drupal.org/tracker?page=2

or, in a perfect world
http://drupal.org/tracker/page/2

Is there a reason for this? Can it be overridden?

Comments

amnon’s picture

You hit the nail on the head. That's one thing I don't like in Drupal.

I'm a programmer and I'm used to counting from 0, yet, to me, it looks very wrong, and confusing, that "page=1" is actually page two :-(

formicin’s picture

you can add url aliases for every page number, but it would be time consuming.
can we hack pathauto for generating this page numbers?

onkare.com

zeitenflug’s picture

If you invoke the first page, you don't have $page set, that's why it is zero. If page 2 was $page=2, then you would have to send $page with every request, even if it is only one page. Every URL of your site would get an additional "$page=1". For most drupal site owners, this looks ugly, thus noone will change it, I guess. Anyway, you don't need the page attribute unless there is more than one page.

This means, if you want to change it for your site, you have to hack it yourself. I guess you could probably work with some kind of hook that decreases/increases the page number. However, the easiest method would be, to install pathauto and to create a function called conf_url_rewrite in your settings file.

$mode will either be set to outgoing or incoming. Increase page for outgoing rewrites and decrease page for incoming rewrites. This should do it.

AltaVida’s picture

Why can't drupal assume internally that if no page value is set then $_GET['page'] should be assumed to be 1. Something like this:

if (!$_GET['page']) {
  $_GET['page'] = 1;
}

That way, for paging purposes there will be no such thing as page=0, which makes sense if you consider that 'page' is a metaphor for pages in a document and there is never a page 0 in any book.

The current implementation is not intuitive, when you hover over the second page in the pager it says "go to page 2" (title attribute) but the url shows up in the status bar as page=1.

Sorry if there is a more appropriate (ie. current) thread for this discussion somewhere but I couldn't find it. Perhaps this is even addressed in 5.0? Does anyone know?

Thanks

hickory’s picture

I agree, and it still works this way in Drupal 5. Unfortunately I haven't been able to decipher pager.inc yet to work out how to change it so that the first page is #1.

rmpel’s picture

Havent read the code for more than 2 minutes, so this is only a direction for a quick-and-dirty hack.

Looks to me there are 2 things that need doing to get page=2 to link to page 2 instead of 3

1. The page processing;
think it is on line 53; $page = isset($_GET['page']) ? $_GET['page'] : '';
this would become; $page = isset($_GET['page']) ? ($_GET['page']-1) : '';
this way calling for page 2 will result in page variable being 1, what the function expects.

2. the link output in the pager
around 362. Havent got a clue how to change it here. The call pager_load_array determines the page numbers I guess.
What needs doing is outoutting page+1 instead of page. that way instead of 1 being output for page 2, 2 is being output.

basically, this is a cosmetic fix. Just increment the number on output, decrement the number on input and you're done. Internally Drupal still uses pages 0 through 4 (for 5 pages) but interface-wise it's 1 through 5.

Again, haven't read the code for very long, so this is just a direction and in no way a complete solution.

Remon.

Edit -> I see after posting that this topic is based on 4.7.x. The line numbers i mentionned are from the 5.0 version. I havent seen the 4.7 version myself so line numbers could be off.
The functions I found are:
Pager_query and
Theme_pager_link

Hope this still can be of use.

batman1983’s picture

So line 363 to line 365 has to be:

 if ($new_page = implode('.', pager_load_array($page_new[$element], $element, explode('.', $page)))) {
    $parameters['seite'] = $new_page+1;
  }

I just tested it, and it works....
Thanks rmpel

EDIT: But you have to care, if you use the Paging module.... I'm working on the problem

LanceLight’s picture

This is the correct fix for this problem: (This is for drupal 5.x, it should be the same in 4.x/6.x as well)

Change

function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
  global $pager_page_array, $pager_total, $pager_total_items;
  $page = isset($_GET['page']) ? $_GET['page'] : '';

To This:

function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
  global $pager_page_array, $pager_total, $pager_total_items;
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  $page--;  //Add $page-- to fix drupal's page 0 problem

Change

function theme_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
   $parameters['page'] = $new_page;
  }

To this:

function theme_pager_link($text, $page_new, $element, $parameters = array(), $attributes = array()) {
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
//    $parameters['page'] = $new_page;
     $parameters['page'] = $new_page + 1; //Add +1 to fix drupal's page 0 problem
  }
zach harkey’s picture

@Lance Would you mind submitting this as a patch?

-zach
--
harkey design

: z

Jean-Philippe Fleury’s picture

rmpel’s picture

Thanks for your patch. Just a reminder to everyone reading this;

This topic is about Drupal 4.7.x
The mentioned patch is for Drupal 7.x

Just my two cents

dipeshyadav’s picture

Start page count from 1 with views pager

go to your_site.com/includes/pager.inc

and this code

function theme_pager_link($variables) {
$text = $variables['text'];
$page_new = $variables['page_new'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$attributes = $variables['attributes'];

$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$parameters['page'] = $new_page;
}

replace to

function theme_pager_link($variables) {
$text = $variables['text'];
$page_new = $variables['page_new'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$attributes = $variables['attributes'];

$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$parameters['page'] = $new_page+1;
}

Soundvessel’s picture

Simply adding + 1 to $new_page does not work. For example, I have a view with 13 items set for 12 a page. With this modification, I click next from the initial page but I get no results because you are simply changing the link and not adjusting the output.