我将通过创建一个页面,然后创建一个节点模板来完成此操作。首先创建一个新节点,然后记录模板名称的 NID。
然后,在您的模板中,创建一个新文件,并按以下方式命名:node--[node id].tpl.php
然后,在该文件中,粘贴以下帮助函数(或者,如果您要在站点的其他地方使用它,也可以将其放在 template.php 中):
/**
* Gets the resulting output of a view as an array of rows,
* each containing the rendered fields of the view
*/
function views_get_rendered_fields($name, $display_id = NULL) {
$args = func_get_args();
array_shift($args); // remove $name
if (count($args)) {
array_shift($args); // remove $display_id
}
$view = views_get_view($name);
if (is_object($view)) {
if (is_array($args)) {
$view->set_arguments($args);
}
if (is_string($display_id)) {
$view->set_display($display_id);
}
else {
$view->init_display();
}
$view->pre_execute();
$view->execute();
$view->render();
//dd($view->style_plugin);
return $view->style_plugin->rendered_fields;
} else {
return array();
}
}
然后将以下代码添加到您的模板中:
<?php
$cars = views_get_rendered_fields('view name', 'default', [...any arguments to be passed to the view]);
foreach ($cars as $car): ?>
<div>Put your mockup in here. It might be helpful to run <?php die('<pre>'.print_r($car, 1).'</pre>'); ?> to see what the $car array looks like.</div>
<?php endforeach;
?>
只需将代码中的占位符更改为您希望标记的任何内容,您就应该设置好!
<?php die('<pre>'.print_r($car,1).'</pre>'); ?>
正如我上面提到的,对阵列打印的样子进行视觉表示总是有帮助的。
我views_get_rendered_fields
一直在我的代码中使用它,因为它允许我完全自定义视图的输出。
提醒:每次创建新模板时,请务必清除缓存。
祝你好运!