Drupal View - 不渲染某些节点的某些字段
我想要实现的目标非常简单,但解释起来有点困难:
- 我想创建一个视图以根据某些条件返回最后 5 个节点
- 我想显示的字段是“标题,摘要和拇指”
- 我只想显示第一个节点的拇指,我不希望其余节点显示拇指
当然通过 CSS 隐藏拇指是愚蠢的。实现这一目标的最佳方法是什么?
What I'm trying to achieve is very simple, but a bit difficult to explain:
- I want to create a view to return the last 5 nodes based on some condition
- The fields I want to show are "Title,Abstract & Thumb"
- I want to show the thumb for only the first node, I don't want the thumb to be displayed for the rest
Of course hiding the thumb via CSS is silly. What is the best way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用视图附件。谷歌一下以了解附件显示是什么。您不需要为视图模块安装任何特殊模块即可获得附件显示。
附件显示是视图中的一种显示类型(如页面、块),只不过它附加到预先存在的视图。因此,您创建的第一个视图显示了标题、摘要和缩略图(并且仅显示 1 个项目)。让附件显示附加在页面显示之后。它的偏移量应为 1(以便跳过第一项),并且不应在字段下有拇指(覆盖字段设置)。它应该显示 4 个项目。偏移量是视图
基本设置
下的一项设置。这将实现您的目标。
也就是说,使用 CSS 隐藏最后三张图像也不是一个坏主意。使用 css 注入器模块。
You need to use Views attachments. Google around to understand what an attachment display is. You don't need to install any special modules for the views module to get the attachment display.
An attachment display is a display type in Views (like Page, Block) except that it gets attached to a pre-existing view. So the first view you create a page display that shows the Title, abstract and thumb (and shows only 1 item). Let the attachment display be attached after the page display. It should have an offset of 1 (so that it skips the first item) and it should not have the thumb under fields (override the fields settings). It should show 4 items. Offset is a setting under
Basic settings
of views.This will achieve your objective.
That said, hiding the last three images using CSS is not a bad idea either. Use the css injector module.
假设 Drupal 6.x...
您是否考虑过构建两个显示:
抱歉,目前没有时间写详细说明。我稍后会回来看看这个想法是否能让你开始......
Assuming Drupal 6.x...
Have you looked into building two displays:
Sorry don't have time to write detailed directions at the moment. I'll check back later to see if this idea gets you started...
您可能需要编辑视图模板来实现此目的。这有点黑暗艺术,但它可能是无需制作附件的最快方法。您很可能会编辑views-view-fields.tpl.php。您可以通过点击视图中的主题:信息链接来获取有关它的更多信息。
视图模板一开始看起来是空的(即使在复制代码之后也是如此),但是您可以通过循环
$view->results
来执行很多操作。You might want to edit the view template to achieve this end. It's a bit of a dark art, but it is probably the fastest way without making attachments. You'll most likely be editing views-view-fields.tpl.php. You can get more info about it by hitting the Theme: Information link in your view.
The view template will look empty at first (even after you copy in the code), but you can do a lot by looping through
$view->results
.