【问题标题】:Drupal: Views combine multiple blocks outputDrupal:视图组合多个块输出
【发布时间】:2011-04-14 23:31:50
【问题描述】:

我正在考虑创建三个不同的块,将它们组合起来,然后随机化输出。

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

显然我已经剪掉了一堆代码,所以请不要对此发表评论。

【问题讨论】:

    标签: drupal drupal-views drupal-blocks


    【解决方案1】:
    /**
     * 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      相关资源
      最近更新 更多