Drupal View - 不渲染某些节点的某些字段

发布于 2024-09-25 13:59:42 字数 183 浏览 4 评论 0原文

我想要实现的目标非常简单,但解释起来有点困难:

  1. 我想创建一个视图以根据某些条件返回最后 5 个节点
  2. 我想显示的字段是“标题,摘要和拇指”
  3. 我只想显示第一个节点的拇指,我不希望其余节点显示拇指

当然通过 CSS 隐藏拇指是愚蠢的。实现这一目标的最佳方法是什么?

What I'm trying to achieve is very simple, but a bit difficult to explain:

  1. I want to create a view to return the last 5 nodes based on some condition
  2. The fields I want to show are "Title,Abstract & Thumb"
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海夕 2024-10-02 13:59:42

您需要使用视图附件。谷歌一下以了解附件显示是什么。您不需要为视图模块安装任何特殊模块即可获得附件显示。

附件显示是视图中的一种显示类型(如页面、块),只不过它附加到预先存在的视图。因此,您创建的第一个视图显示了标题、摘要和缩略图(并且仅显示 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.

面如桃花 2024-10-02 13:59:42

假设 Drupal 6.x...

您是否考虑过构建两个显示:

  1. 页面显示,没有缩略图字段,限制为任意数量的项目,偏移量 = 1
  2. 带有缩略图字段的附件显示,限制为 1 个项目,偏移量 = 0
  3. 附件设置:位置:之前;附加到:页面

抱歉,目前没有时间写详细说明。我稍后会回来看看这个想法是否能让你开始......

Assuming Drupal 6.x...

Have you looked into building two displays:

  1. A page display, without the thumbnail field, limited to whatever number of items, offset = 1
  2. An attachment display with the thumbnail field, limited to 1 item, offset = 0
  3. Attachment settings: Position: Before; Attach to: Page

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...

半﹌身腐败 2024-10-02 13:59:42

您可能需要编辑视图模板来实现此目的。这有点黑暗艺术,但它可能是无需制作附件的最快方法。您很可能会编辑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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文