Drupal 7,不确定如何根据查询数据正确设置我的输出主题
我一直在使用视图来选择性地返回节点,但现在我想返回我的节点并使用分类术语作为组标题。无论如何,我看不到让视图为我执行此操作,然后在一个页面上创建多个视图。
所以我想我应该纠正一个模块。我已经编写了 SQL 来返回正确的节点,但我无法弄清楚如何将它们正确发送到主题引擎。我想要一些关于如何解决这个问题的建议,我的教程书中有构建列表的示例,如下所示。
foreach ($result as $row2) {
$items[] = l($row2->title,'node/'.$row2->nid.'/edit');
}
return array('#markup' => theme('item_list',array('items' => $items)));
现在我想在 Teaser 模式下返回我的节点附加图像文件和节点的标题,另外(我不想超出自己)我可能还需要在标题中附加几个附加节点字段。应该很容易吧?我根本无法解决。
我已经通过使用我确定是非 drupal 方法(看起来有点像这样)来解决它(有点),问题是我无法让我的输出与 ColorBox 模块一起使用,所以我在想如果我能得到官方的 Teaser 节点数据,它可能会工作得更好,而且我会感觉更好,因为我知道我正在以 drupaly 的方式做事:)
foreach ($result as $row2) {
$items .= '<img title="'.$row2->title.' '.$row2->fielddata.'" alt="'.$row2->title.'" src="http://localhost/theme/sites/default/files/styles/thumbnail/public/field/image/'.$row2->filename .'"></a>';
$items .= '</div></div></div></div>';
}
return array('#markup' => $items);
非常感谢您花时间帮助我,并提前致谢。< /强>
I’ve been using Views to selectively returned nodes, but right now I want to return my nodes and use the Taxonomy term as a group header. I can't see anyway to get Views to do this for me, other then create multiple views on one page.
So I thought I'd right a module. I've written the SQL to return the correct nodes, but I can't work out how to send them to the themeing engine properly. I would like some advice on how to go about this, my tutorial book has examples of building a list as shown below.
foreach ($result as $row2) {
$items[] = l($row2->title,'node/'.$row2->nid.'/edit');
}
return array('#markup' => theme('item_list',array('items' => $items)));
now I want to return my nodes attached image file in Teaser mode, and the title of the node, plus (and I dont want to get ahead of myself) I may also want a couple of the addition node fields appended to the title. Should be easy right? I can't work it out at all.
I have wrangled my way around it (a bit) by using what I'm sure is a non drupal method which looks a bit like this, trouble is I can't get my output to work with ColorBox module, so I'm thinking if I can get official Teaser node data out it might work better, and i'd feel better knowing I was doing things in a drupaly way :)
foreach ($result as $row2) {
$items .= '<img title="'.$row2->title.' '.$row2->fielddata.'" alt="'.$row2->title.'" src="http://localhost/theme/sites/default/files/styles/thumbnail/public/field/image/'.$row2->filename .'"></a>';
$items .= '</div></div></div></div>';
}
return array('#markup' => $items);
Really appreciate any time you take to help me out and thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面的代码应该有帮助。如果您还没有,请安装 devel 模块,它为您提供了一个很棒的功能,称为
dpm()
它将把数组/对象的内容打印到消息区域。希望有帮助
The following code should help. If you don't already have it, install the devel module, it gives you a wonderful function called
dpm()
which will print the contents of an array/object to the messages area.Hope that helps
您可以获得按分类术语对返回的节点进行分组的视图。假设您使用的是
field
视图类型,只需添加分类字段,然后添加Format:Unformatted list | 。设置
单击右侧的“设置”,然后选择您的分类字段作为分组字段。注意:如果您不使用
字段
视图类型,或者不使用无格式列表
,那么说明将是上述内容的变体。You can get views to group the returned nodes by the taxonomy term for you. Assuming you are using a
field
view type, just add the taxonomy field and then where it saysFormat:Unformatted list | Settings
click on Settings at the right hand side and choose your taxonomy field as the grouping field.Note: if you are not using a
field
view type, or if you are not usingunformatted list
then the instructions will be a variation of the above.