1

In order to apply pagination on nodes which get rendered into block, I am using pager_default_initialize method. Basically I have written a query, execute that query and after that write pager_default_initialize() function. But it is not applying limit to content per page. i.e. "paging" is not working.

    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
          ->entityCondition('bundle', $content_type)
          ->propertyCondition('status',1);
  $results = $query->execute();
pager_default_initialize(count($results['node']), 2);

here, the count of nodes is 4 and I want to display only 2 nodes with pagination.

return theme('calender', array('calender' => $output)).theme('pager');

Here I'm using theme('pager') for pagination interface.

Pagination UI is displayed, but I'm not able to put limit "2" to the no. of count of nodes. Any suggestion where I went wrong?

3

If your motive is to create a pager for those results, I suggest you to use ->pager() on your EntityFieldQuery.

See this question EntityFieldQuery display pager

if ($type == 21) { 
  $query = new EntityFieldQuery(); 

  $entities = $query->entityCondition('entity_type', 'node')
    ->propertyCondition('type', 'product') 
    ->fieldCondition('field_razred', 'tid', array (607,608,609,610), 'IN')
    ->pager(10) // this is the bit you're missing
    ->execute(); 

  $nodes = node_load_multiple(array_keys($entities['node'])); 
  print render(node_view_multiple($nodes, 'teaser')) . theme('pager');
}

If you necessarily want to use pager_default_initialize(), see this post Creating pager in Drupal (without db_select() and PagerDefault)

$per_page = 10;
// Initialize the pager
$current_page = pager_default_initialize(count($rows), $per_page);
// Split your list into page sized chunks
$chunks = array_chunk($rows, $per_page, TRUE);
// Show the appropriate items from the list
$output = theme('table', array('header' => $header, 'rows' => $chunks[$current_page]));
// Show the pager
$output .= theme('pager', array('quantity',count($rows)));

Hope these examples will help you.

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.