Drupal - 获取视野

Drupal - get the field of view

您好!

我正在尝试获取视野
有一个代码:

$variables = module_invoke('views', 'block_view', 'news-block');   
print render($variables['content']);

显示单元软件。

这样的结论能不能得到领域。而是从变量 $variables

获取跨字段的视图

提前感谢大家

对不起我的英语。

您可以使用views_get_view_result函数:

$view = views_get_view_result($name, $display_id); // returns an array conatining the result of the view
print_r($view);

如果你更喜欢获取整个节点对象,你可以使用 node_load 函数和每行的 nids:

$view = views_get_view_result($name, $display_id); // returns an array conatining the result of the view
$nodes = array(); // create an empty array to push each node objects
foreach ($view as $row) {
    $node = node_load($row->nid); // get the node object by nid
    $nodes[] = $node; // push node to $nodes array
}
print_r($nodes);

另见:https://drupal.stackexchange.com/questions/32825/get-a-views-result-using-php-code-and-iterate-the-proper-way