官方文档:https://drupal.org/node/1655012
专门的模块:Embed Views Display
--------- last updated at 2013-8-8
最新views 3.x(drupal 7)的变动
例子: 不显示pager,仅显示6条记录,如下:
$view->display_handler->set_option('pager', array('type'=>'some','options' => array('items_per_page' => 6)));
========================================================================
$view = views_get_view('views_name');
$view->set_display('default');
$view->display_handler->set_option('items_per_page', 3);
$view->display_handler->set_option('use_pager', FALSE);
print $view->preview(NULL, array($arg));
要返回查询的行数,可调用:print $view->total_rows;
(要注意的是:当views使用pager才自动计算总行数;如果use_pager=FALSE,需强制指定:$view->get_total_rows = TRUE)
其它的一些写法:
官方推荐的:print views_embed_view('view_name','default',arg(1));
单独指定Arguments:$view->set_arguments(array(arg1,arg2));
又一种写法:
$view = views_get_view('video');
print $view->execute_display('default', $args);
补充:views参数可另外指定:
$view->set_arguments(array($tid));
$view->preview();
评论
有个教学录像,老外就喜欢看录像~ http://got
有个教学录像,老外就喜欢看录像~
http://gotdrupal.com/videos/drupal-views-arguments
另一个例子
Views导出的代码,可以进一步深入研究: $view
Views导出的代码,可以进一步深入研究:
$view = new stdClass();
$view->name = 'Archive';
$view->descrīption = 'Monthly Archive';
$view->access = array (
0 => '1',
1 => '2',
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = '按月归档';
$view->page_header = '';
$view->page_header_format = '4';
$view->page_footer = '';
$view->page_footer_format = '4';
$view->page_empty = '';
$view->page_empty_format = '4';
$view->page_type = 'teaser';
$view->url = 'archive';
$view->use_pager = TRUE;
$view->nodes_per_page = '50';
$view->block = TRUE;
$view->block_title = 'Blog 归档';
$view->block_header = '';
$view->block_header_format = '4';
$view->block_footer = '';
$view->block_footer_format = '4';
$view->block_empty = '';
$view->block_empty_format = '4';
$view->block_type = 'list';
$view->nodes_per_block = '5';
$view->block_more = TRUE;
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
array (
'type' => 'monthyear',
'argdefault' => '5',
'title' => '按月归档',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'blog',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;
How to see datetime cache changed?(答案未测试)
views的官方api文档
http://api.drupal.org/api/views/views.module/function/views_block_view/7