質問

How can I make the pager numbers match the URI string?

For example : When I click on number 3 in pager to turn to page 3 but the the URI is "?page=2" instead of "?page=3". This pagination isn't normal as any other pagination I've met before. How can I fix it?

Thanks!!!

役に立ちましたか?

解決

You could do it by implementing hook_url_outbound_alter(), and hook_url_inbound_alter().

With the first hook, you alter the links that are being output from Drupal; you would increase the value of $options['query']['page'].
With the second hook, you alter the links being received from Drupal; you should find the '?page=' string in the URL, and decrease the number after that string.

Keep in mind that $_GET['page'] can be a string like '1,2,4,5,6' if the page has more than one pager. See the code of pager_find_page().

Also, hook_url_outbound_alter() receive the query parameters in $options, while hook_url_inbound_alter() receives just a string for the URL, which also contains the query part.

他のヒント

The page attribute in the URL is used directly in the query, so if ommitted, page will get 0 as a value. It's normal because Drupal do pagin things like this.

Now if you need to change this, you have to work arround query alters for every query, to add +1 to the limit() or range() methods.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top