6

I have problem to understand how I should use theme('pager') as explained on EntityFieldQuery display pager.

I can't make it work (display pager and links to resulting pages).

Does pager(10) in EntityFieldQuery automatically invoke the pager? Should it be displayed with print(theme('pager'))?

Is this functionality included in Drupal core (7.15)?

I am doing my queries in template.php and injecting the query result in article.tpl.php through a variable.

As a workaround, I am thinking of doing two queries, one to find out what the number of nodes that meet a condition is, output links with numbering, attach the variable to those links, read the variable in another query and select the resulting nodes with range($i,$j).

7

Does pager(10) in EntityFieldQuery automatically invoke the pager?

Yes; it even avoids the usual problem of multiple pagers on a single page conflicting, by getting a new delta from the PagerDefault class.

Should it be displayed with print(theme('pager'))?

Yes (but obviously only if there is more than one page worth of results to display).

Is this functionality included in Drupal core (7.15)?

Yes.

This works perfectly for me:

$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'node')
  ->pager(10);

$results = $query->execute();
$nodes = node_load_multiple(array_keys($results['node']));

$build = array(
  'nodes' => node_view_multiple($nodes),
  'pager' => array(
    '#theme' => 'pager',
  )
);

That's returned from a menu callback function, so will be passed through drupal_render(). When it does so, a list of node teasers is displayed with the expected pager right below.

If the same example doesn't work for you then there must be something wrong with your installation, or something in a custom/contributed module conflicting with the core pager system.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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