Drupal:视图组合多个块输出

时间:2011-04-14 23:31:50

标签: drupal drupal-views drupal-blocks

我正在寻找创建三个不同的块,组合它们然后随机化输出。

EG:

第1区:<div id="col1">

第2栏:<div id="col2">

第3区:<div id="col3">

将三者组合并随机化,使输出看起来像

<div id="col2">, <div id="col1">, <div id="col2">, <div id="col3">等......

显然我已经删除了一堆代码,所以请不要对此进行评论。

1 个答案:

答案 0 :(得分:2)

/**
 * Implementation of hook_block().
 */
function _report_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks['custom_block'] = array(
        'info' => t('My custom block'),
        'weight' => 0,
        'status' => 1,
        'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE,
    );
    return $blocks;
  }
  else if ($op == 'view') {
    switch($delta){
      case 'custom_block':
        $data['subject'] = t('Enjoy your life :)');
        $data['content'] = my_block_content();
        return $data;
        break;
    }
  }
}

function my_block_content(){
  $blocks = array('block_1', 'block_2', 'block_3');
  $items = array();

  $view = views_get_view('my_view');
  foreach($blocks AS $block){
    $view->set_display($block);
    $view->execute();
    $items[] = $view->result;
  }
  shuffle($items);
  return $items;
}