首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Drupal -获得视野

Drupal -获得视野
EN

Stack Overflow用户
提问于 2015-10-12 14:49:39
回答 1查看 89关注 0票数 1

你好!

我正在努力获取视图的范围

有一个守则:

代码语言:javascript
复制
$variables = module_invoke('views', 'block_view', 'news-block');   
print render($variables['content']);

显示单元软件。

是否有可能得到这样的结论。而是从变量$variables跨字段获取视图。

提前感恩

对不起我的英语。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-15 12:01:00

您可以使用views_get_view_result函数:

代码语言:javascript
复制
$view = views_get_view_result($name, $display_id); // returns an array conatining the result of the view
print_r($view);

如果您希望获得整个节点对象,则可以在每一行的nids中使用node_load函数:

代码语言:javascript
复制
$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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33084072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档