2015-10-12 32 views
1

您好!Drupal - 獲得視野

我想獲得的意見
領域有一個代碼:

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

顯示單元的軟件。

是否有可能以這樣的結論獲得該領域。而是從可變$variables

提前獲得在田野上的觀點都感謝

對不起,我的英語水平。

+0

您是否想要自定義視圖的任何特定字段的視圖? –

回答

1

可以使用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

+0

謝謝大家的回答和評論! –