在drupal 7中的同一模板文件中显示多个分页

时间:2013-05-31 11:35:28

标签: php drupal-7 pagination

在我的自定义模板tpl文件中,我显示了两个部分(div内容)的数据,一个来自我的自定义模块的每个功能。 数据也有分页,如下所示。

最初只会显示一个数据块。除非用户单击页面中的选项卡,否则其他数据块将隐藏在页面上。    现在我的问题是,如何在同一页面中为每个块显示单独的分页?

如果我点击第1块中的页面链接并转到其页面,则不得影响其他块的分页链接。 如何在Drupal 7中实现这一目标?

// my custom module code below
// function one
func one() { 
$page = strtolower($page);
$query  = db_select('keyword', 'k');    
$query->groupBy('k.res');
$stories = $query->extend('PagerDefault')->limit(10)->execute();
return $stories;
}

// function two
func two() { 
$page = strtolower($page);
$query  = db_select('videos', 'v'); 
$query->groupBy('v.res');
$videos= $query->extend('PagerDefault')->limit(10)->execute();
return $videos;
}
// in my custom template page
// below is first section in same page
$block_content = fun one(arg(1));
$args = array( 'parameters' => array('pg' => 'one'));
print (theme ('pager',$args));
foreach($block_content as $content)
{
  // doing something to display
}
print (theme ('pager',$args));

// below is second section in same page
$block_content = fun two(arg(1));
$args = array( 'parameters' => array('pg' => 'two'));
print (theme ('pager',$args));
foreach($block_content as $content)
{
  // doing something to display
}
print (theme ('pager',$args));

1 个答案:

答案 0 :(得分:2)

您可以使用PagerDefault::element()方法为寻呼机设置唯一的元素ID:

// First one
$stories = $query->extend('PagerDefault')->element(0)->limit(10)->execute();

// Second one
$videos = $query->extend('PagerDefault')->element(1)->limit(10)->execute();

然后在主题调用中使用相应的元素ID:

// First one
$args = array('element' => 0, ...);
print theme('pager', $args);

// Second one
$args = array('element' => 1, ...);
print theme('pager', $args);