Drupal Views:获取与当前节点具有相同分类的节点

发布于 2024-09-27 10:55:40 字数 138 浏览 6 评论 0 原文

我有一个带有分类术语的内容类型。它是一个选择列表,因此它只能有一种分类法 - 至少是该词汇表。现在我需要构建一个视图,列出具有相同分类的所有节点。

我认为这不会太难,因为它听起来很基本。但我无法让它发挥作用。有什么想法吗?我试图避免为此编写模块。

I have a Content-Type with taxonomy-terms. It's a select-list, so it can have only one taxonomy - at least of that vocabulary. Now I need to build a view that lists all nodes with the same taxonomy.

Thought that this wouldn't be too hard since it sounds pretty basic. Yet I can't get it working. Any ideas? I'm trying to avoid writing a module for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

一个人的旅程 2024-10-04 10:55:40

虽然这在技术上可以通过 Views 2 实现,如其他一些答案中所述,但 Views 3 内置了此集成。

您可以为分类术语 id 创建参数,然后选择“提供默认参数” 。然后,这将为您提供一个选项“来自 URL 的分类术语 ID”和“从节点页面加载默认参数...”

这将允许您采用以下分类一个页面并将其作为参数传递给您的视图块。

注意:Views 3 目前处于 Alpha 3 阶段,但根​​据我的经验,它处于相对稳定的状态,并且我正在生产站点上使用它。如果它具有您认为有用的上述功能,请使用它、测试它并在遇到任何问题时提交错误/补丁!

While this was technically possible with Views 2 as described in some of the other answers, Views 3 has this integration built in.

You can create an argument for the taxonomy term id and then choose "Provide default argument". This will then give you an option for "Taxonomy Term ID from URL" and "Load default argument from node page..."

This will allow you to take the taxonomy of a page and pass that as an argument to your view block.

Note: Views 3 is currently in Alpha 3 but in my experience is at a relatively stable state and I am using it on production sites. If it has features like the one above that you find useful please use it, test it and submit bugs/patches if you encounter any issues!

青衫儰鉨ミ守葔 2024-10-04 10:55:40

此答案适用于 Views 版本 2 或更高版本。首先,您需要安装 Views Attach ( http://drupal.org/project/views_attach )。在继续操作之前,请先阅读有关视图附加的内容。这个视频可以很好地解释视图附加 http://mustardseedmedia.com/podcast/episode37

现在我们得到附加到视图。请先启用视图附加模块,然后再继续。本质上,Views Attach 在节点末尾附加一个视图。在我们的例子中,我们的视图将是具有相同术语的其他文章的列表。

我们本质上需要将节点的分类术语“传递”到视图。将您的词汇表名称命名为 MyVocab

制作视图的步骤。

  1. 让我们调用该视图 display_other_articles_with_same_taxonomy
  2. 添加节点内容类型的显示(启用视图附加后可用)。这是一种类似于块和页面显示的显示,但具有将自身附加到节点的特殊能力。

节点内容显示中进行以下设置。

Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No

您应该在参数下选择使用视图附加到的节点中的令牌。让标记为[term-id] 这是“顶级分类术语的ID”。这非常重要!本质上,您将从 MyVocab 传递节点的分类术语(请参阅 http://groups.drupal.org/node/11788#comment-38332)。如果它的权重最低,则分类词汇将是节点编辑表单的分类部分中的第一个词汇。添加参数分类:术语 ID

添加您感兴趣的字段,例如Node: Title。确保通过勾选将此字段链接到其节点节点:标题制成超链接。

因此,此视图要做的是:

  1. 从<中获取分类术语当前正在查看的节点中的 code>MyVocab 词汇表
  2. 将其作为参数传递给视图 display_other_articles_with_same_taxonomy
  3. 列出与正在显示的节点具有相同分类术语的所有节点。

就是这样!

如果您使用的是 Views 3(在撰写本文时目前处于 alpha3 状态)并且您想要一个块(现在这些文章在节点主体末尾有相同的分类术语)您可以这样做按照以下方式:

  1. 忘记视图附加...它不需要
  2. 添加块视图。它应包含与上述节点内容显示说明相同的参数、字段和过滤器。
  3. 您需要稍微修改参数Taxononomy:Term Id的设置:在如果参数不存在则采取的操作:下选择[x]提供默认参数。选择[x]来自 URL 的分类术语 ID。现在确保取消选择[]从术语页面加载默认参数并且[x]从节点页面加载默认参数,这对于相关分类块很有用。另外[ x]按词汇表限制术语并选择系列词汇表。
  4. 确保为该块命名并将其放置在适当的区域中。

注意:这个答案是我在 如何在包含的节点上显示 NodeQueue 块? 在该场景中,要求是显式选择相关文章并按特定顺序列出。它有点复杂,并且使用我们在这里根本不需要的 Nodequeues。

This answer works in Views version 2 or higher. First you need to install Views attach ( http://drupal.org/project/views_attach ). Please read about Views attach before proceeding further. Views attach is best explained by this video http://mustardseedmedia.com/podcast/episode37

Now we get to Views attach. Please enable the views attach module before proceeding. Essentially Views attach attaches a view at the end of the node. In our case our view will be a listing of other articles with the same term.

We will essentially need to "pass" the taxonomy term of the node to the view. Let the name of your Vocabulary be called MyVocab.

Steps to make the view.

  1. Lets call the view display_other_articles_with_same_taxonomy.
  2. Add a display of type Node Content (available after enabling Views attach). This is a display just like block and page displays but with special ability of attaching itself to the node.

Make the following settings in the Node Content Display

Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No

You should select Use tokens from the node the view is attached to under Arguments. Let the token be [term-id] This is the "ID of top taxonomy term". This is very important!! Essentially you are going to be passing the taxonomy term of the node from the MyVocab (See http://groups.drupal.org/node/11788#comment-38332). If it has the lowest weight, the taxonomy vocabulary will be the first vocabulary in the taxonomy section of your node edit form. Add an argument Taxonomy: Term Id.

Add the fields you are interested in e.g. Node: Title. Make sure the Node: Title is made into a hyperlink by ticking Link this field to its Node

So what this view is going to do is:

  1. Take the taxonomy term from the MyVocab vocabulary in the Node that is currently being viewed
  2. Pass that as argument to the view display_other_articles_with_same_taxonomy
  3. List all the nodes that have the same taxonomy term as the node being displayed.

Thats it!

If you're using Views 3 (currently at alpha3 at the time of writing) and you want a block (right now the articles have same taxonomy term come at the end of node body) you can do it in the following fashion:

  1. Forget about views attach... its not required
  2. Add a block view. It should contain the same argument, fields and filters as the instructions above for the Node Content display.
  3. You need to modify the settings for the argument Taxononomy: Term Id just slightly: Under Action to take if argument is not present: choose [x] Provide Default Argument. Choose [x] Taxonomy Term ID from URL. Now make sure [] Load default argument from term page is unselected and [x] Load default argument from node page, thats good for related taxonomy blocks. Also [x]Limit terms by vocabulary and choose the Series vocabulary.
  4. Make sure you name the block and put it in the appropriate region.

Note: This answer is subset of the answer I provided at How to just show NodeQueue block on included nodes? In that scenario the requirement was that the related articles are explicitly selected and listed in a particular order. Its a little more complex and uses Nodequeues which we don't need here at all.

那伤。 2024-10-04 10:55:40

使用关系

  1. 节点 1 ->关系1->术语 // 这将是关系 -> 分类 -> 术语 术语
  2. ->关系2->节点 2 // 这将是关系->节点->节点
  3. 参数 NID,用于过滤节点 1
  4. 字段或关系 2 上的节点完整视图(您将在字段添加表单上看到选择框,以确定要使用的节点)

Use relationships

  1. Node 1 -> Relationship 1 -> Term // This will be relationships->taxonomy->term
  2. Term -> Relationship 2 -> Node 2 // This will be relationships->node->node
  3. Argument NID to filter NODE 1
  4. Fields or node full view on Relationship 2 (you will see select box on field adding form, to determinate what NODE to use)
世界和平 2024-10-04 10:55:40

视图为您提供添加过滤器的选项。单击视图管理 UI 的过滤器区域中的加号,从列表中选择分类法,选中术语或 ID,然后填写您需要作为过滤依据的值。

编辑(用于明确说明):

  1. 首先,在要从尝试过滤的节点中显示的字段部分下添加所需的必要字段,例如节点标题等。

  2. ,单击加号并选择“分类法”

  3. 检查分类法:术语并单击添加

  4. 单击更新

在预览区域中通过添加进行测试参数并单击预览。如果它不起作用,则您的节点没有附加分类法,您的视图模块已损坏,或者您没有遵循指示。

Views gives you the options to add filters. Click the plus sign in the filters area of the views admin UI, select Taxonomy from the list, check either Term or ID, and fill in the value that you need to filter by.

EDIT (for explicit instructions):

  1. First, add the necessary fields that you want under the fields section that you want to display from the nodes that you are trying to filter such as node title, etc.

  2. Under Arguments, click the plus sign and select Taxonomy

  3. Check Taxonomy: Term and click Add

  4. Click Update

In your preview area test it out by adding an argument and clicking preview. If it doesn't work, your nodes do not have attached taxonomy, your views module is corrupted, or you didn't follow directions.

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