By zach harkey on
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
...
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 :-(
can we hack pathauto for
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
It has to be
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.
does it really have to be?
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:
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
pager.inc
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.
Partial solution
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.
So line 363 to line 365 has
So line 363 to line 365 has to be:
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
This is the correct fix for
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
To This:
Change
To this:
@Lance Would you mind
@Lance Would you mind submitting this as a patch?
-zach
--
harkey design
: z
Patch submitted
I've submitted the patch. See #385270: Make the GET page variable consistent with the real page number
Thanks for your patch. Just a
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
Start page count from 1 with views pager
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;
}
Simply adding + 1 to $new
Simply adding + 1 to
$new_pagedoes 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.