2011-04-14 63 views
1

我正在寻找创建三个不同的块,结合它们,然后随机输出。Drupal:视图结合多个块输出

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">等..

很明显我已经削减了一堆代码,所以请不要对此发表评论。

回答

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; 
} 
+0

Good work dobeerman – 2011-04-15 18:17:18