我有一个带有分类术语的内容类型。这是一个选择列表,所以它只能有一个分类法——至少是那个词汇表。现在我需要构建一个视图,列出所有具有相同分类的节点。
认为这不会太难,因为它听起来很基本。但是我无法让它工作。有任何想法吗?我试图避免为此编写模块。
我有一个带有分类术语的内容类型。这是一个选择列表,所以它只能有一个分类法——至少是那个词汇表。现在我需要构建一个视图,列出所有具有相同分类的节点。
认为这不会太难,因为它听起来很基本。但是我无法让它工作。有任何想法吗?我试图避免为此编写模块。
虽然如其他一些答案中所述,Views 2 在技术上是可行的,但 Views 3 内置了这种集成。
您可以为分类术语 id 创建一个参数,然后选择“提供默认参数”。然后,这将为您提供“来自 URL 的分类术语 ID”和“从节点页面加载默认参数...”的选项
这将允许您获取页面的分类并将其作为参数传递给您的视图块。
注意:Views 3 目前处于 Alpha 3 阶段,但根据我的经验,它处于相对稳定的状态,我正在生产站点上使用它。如果它具有您认为有用的上述功能,请使用它,测试它并在遇到任何问题时提交错误/补丁!
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.
display_other_articles_with_same_taxonomy
. 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:
MyVocab
vocabulary in the Node that is currently being vieweddisplay_other_articles_with_same_taxonomy
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:
Node Content
display.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. 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.
使用关系
视图为您提供添加过滤器的选项。单击视图管理 UI 的过滤器区域中的加号,从列表中选择分类,检查术语或 ID,然后填写您需要过滤的值。
编辑(用于明确说明):
首先,在要从您尝试过滤的节点(例如节点标题等)显示的字段部分下添加所需的字段。
在 Arguments 下,单击加号并选择 Taxonomy
检查分类:术语并单击添加
点击更新
在您的预览区域中,通过添加参数并单击预览来测试它。如果它不起作用,您的节点没有附加分类,您的视图模块已损坏,或者您没有按照指示进行操作。