I'm doing the usual sort of Drupal 7 DB API pager stuff to work through a bunch of items, e.g (greatly simplified):

$the_nodes = db_select('node', 'n')->extend('PagerDefault');
-- conditions, fields, etc. --
return $the_nodes->execute()->fetchCol();

and then the appropriate rendering code to make the pager study appear, of course.

What I'd like to be able to do is, from inside the function containing this query, to be able to tell which page of the pager I'm on -- in particular, if I'm on the first page, or not. The idea is to insert a couple of other records at the beginning of the list, but only on the first page.

So: Does anybody know if this is possible? Thanks!

2 Answers 2


Instead of access $_GET directly, you should use pager_find_page().

  • EXCELLENT! Exactly what I was looking for. Thanks!
    – Jim Miller
    May 17, 2018 at 5:02

For future reference: I figured this out. The key is to (duh) check the URL. The first page of a pager looks like:


while the second looks like:


and so on. So, checking to see if $_GET['page'] is set (or, for paranoia's sake, has a non-zero value) will tell you if you're on the first page or something else. Comments/criticisms are welcome, but I think this does it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.