如何只在包含的节点上显示 NodeQueue 块?
在我的博客上,我有一系列关于一个共同主题的帖子,我想链接加上一个通用的导航块,让读者可以轻松地向前或向后跳过系列.
On my blog I have a series of posts on a common subject that I'd like to link together with a common navigation block, so that readers can easily jump forwards or backwards through the series.
我使用 NodeQueue 按顺序收集所有博客条目.将相关块放在我的侧边栏中为我提供了我想要的导航,但块会出现在我网站的每个页面上.
I've used NodeQueue to collect all the blog entries together in sequence. Putting the associated block in my sidebar gives me the navigation that I want BUT the block appears on every page of my site.
我想做的是限制块的可见性,使其仅出现在包含在队列中的页面上.我该怎么做?
What I want to do is limit the visibility of the block so that it only appears on pages that are included in the queue. How can I do this?
我知道 NodeQueue 使用 Views 创建它的块,所以我想答案可能需要更多使用视图而不是 NodeQueue.如果有一个模块可以满足我的需求,那就太好了.如果答案需要 PHP(例如,用于配置块可见性),那么我需要一些帮助.
I know that NodeQueue creates it's blocks using Views, so I guess the answer might be more to do with using Views than NodeQueue. If there's a module that does what I need, that'd be great. If the answer requires PHP (say, for configuring block visibility) then I'll need some handholding.
该博客在 Drupal 6.19 上运行,我确实有一个测试实例,我可以在接触实时站点之前进行尝试.
The blog is running on Drupal 6.19 and I do have a test instance I can try things out on before touching the live site.
推荐答案
好吧,虽然我认为这是一个优雅的解决方案,但有点冗长.我希望它不会吓到你——它真的并不复杂,但与代码不同,它很难用文字解释.弄清楚这一点很有趣.此答案适用于 Views 版本 2 或更高版本.本质上,该解决方案结合了两个模块
Ok this is a slightly lengthly though I think elegant solution. I hope it doesn't scare you off -- Its really not complex but unlike code its difficult to explain in text. It was fun figuring this out. This answer works in Views version 2 or higher. Essentially the solution combines two modules
- 视图附加(http://drupal.org/project/views_attach)
- Nodequeue(特别是分类队列)
在继续之前,请阅读有关视图附加的信息.此视频对观看次数进行了最好的解释 http://mustardseedmedia.com/podcast/episode37
Please read about Views attach before proceeding further. Views attach is best explained by this video http://mustardseedmedia.com/podcast/episode37
分类队列只不过是为词汇表中的每个分类术语自动创建的节点队列.假设我们有一个名为 My Lists
的分类节点队列.假设您有一个名为 Series
的词汇表,它有 3 个术语:Apache Solr 教程系列
、CSS 技巧和技术系列
、Drupal查看提示系列
.如果 My Lists
使用 Series
作为其分类源,那么将创建 3 个子队列 - 每个术语一个.
A Taxonomy Queue is nothing but a Nodequeue that is automatically created for each taxonomy term in a vocabulary. Let say we have a taxonomy nodequeue called My Lists
. Lets say you have a Vocabulary called Series
and it has 3 terms: Apache Solr Tutorial Series
, CSS Tips and Techniques Series
, Drupal Views Tips Series
. And if My Lists
uses the Series
as its taxonomy source then 3 sub-queues will be created -- one for each term.
在您的博客上,您将拥有多个系列的文章(您称之为具有共同主题"的文章).每个系列将独立于另一个系列.每个系列将包含 2 个或更多博客的列表.重要的是要注意,在我提出的解决方案中,博客只能成为 1 系列的一部分——我希望没问题.我们正在使用基于 Nodequeue 的解决方案,因为您要求系列中博客的列表顺序很重要并且必须保留.
On your blog you will have multiple series of articles (you call it articles with a "common subject"). Each series will be independent from another series. Each series will contain lists of 2 or more blogs. It is important to note that in my proposed solution it will only be possible for a blog to be part of 1 series -- I hope that is ok. We are using a Nodequeue based solution because of your requirement that order of listing of the blogs in the series is important and has to be preserved.
首先,您需要创建一个词汇表(假设我们称之为Series
).每次创建一系列新博客时,您都会创建一个新的分类术语,例如Apache Solr 教程系列
、CSS Tips and Techniques Series
等.确保系列
词汇适用于你的博客
内容类型.
First you will need to create a vocabulary (lets say we call it Series
). Every time you create a new series of blogs you will create a new taxonomy term e.g. Apache Solr Tutorials Series
, CSS Tips and Techniques Series
etc. Make sure that the Series
vocabulary is applicable to your blog
content type.
您现在需要创建分类队列.只需在模块列表中启用 Smartqueue Taxonomy
.它带有标准的 Nodequeue 模块.单击内容管理 > 节点队列 > 分类队列.将队列命名为 My Lists
.确保选择 Series
作为词汇表.您可以将队列的长度保留为 0
(无限制),因为每个博客系列中可以包含任意数量的博客.现在:
You now need to create taxonomy queue. Simply enable Smartqueue Taxonomy
in the modules list. It comes with standard Nodequeue module. Click on Content Management > Nodequeue > taxonomy queue. Name the queue My Lists
. Make sure you select Series
as the Vocabulary. You can leave the length of the queue to be 0
(unlimited) because each series of blogs can have any number of blogs in it. Now:
链接添加到队列"文本:
putAdd to %subqueue
链接从"队列文本中删除:
put从 %subqueue 中删除
Link "add to queue" text:
putAdd to %subqueue
Link "remove from" queue text:
putRemove from %subqueue
这是一件很方便的事情.它会在每个 blog
节点的底部为您提供链接,以便在适当的分类队列中添加或删除.因此,如果一篇博客文章有分类术语CSS Tips and Techniques
,它将在完整节点页面(甚至预告视图)的底部获得一个链接,因此可以将其添加到CSS 技巧和技巧
My Lists
节点队列中的子队列.
This is sort a convenience thing. It will give you links at the bottom of each blog
node to add or remove from the appropriate taxonomy queue. So if a blog article has got the taxonomy term CSS Tips and Techniques
it will get a link at the bottom of the full node page (or even teaser view) so it can be added it to the CSS Tips and Techniques
subqueue in the My Lists
nodequeue.
这完成了分类队列的设置.
This completes the setup for taxonomy queues.
现在我们进入视图附加.请在继续之前启用视图附加模块.本质上,Views attach
在节点的末尾附加了一个视图.在我们的例子中,我们的视图将是该系列其他文章的列表(仅当博客是系列的一部分时).
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 in the series (only if the blog is part of a series).
我们基本上需要将节点的分类术语传递"给视图.该分类术语将在 My Lists
节点队列中选择适当的子队列.该子队列中的所有项目都将按照您指定的确切顺序显示(通过标准 Nodequeue 界面).
We will essentially need to "pass" the taxonomy term of the node to the view. This taxonomy term will select the appropriate subqueue in the My Lists
nodequeue. All items in that subqueue will be shown in the exact order as specified by you (via the standard Nodequeue interface).
制作视图的步骤.
- 让我们调用视图
display_other_blogs_in_series
. - 添加
Node Content
类型的显示(启用视图附加后可用).这是一种类似于块和页面显示的显示,但具有将自身附加到节点的特殊能力.
- Lets call the view
display_other_blogs_in_series
. - 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.
在Node Content Display
Node content settings
Node types: blog
Build modes: Teaser, Full node
Arguments: token
Show title: No
您应该在参数下选择使用视图附加到的节点中的标记
.让标记为 [term-id]
这是顶级分类术语的 ID".这是非常重要的!!本质上,您将从 Series
词汇表(例如 CSS Tips and Techniques)中将博客节点的分类术语作为参数传递给视图.为此,Series
词汇必须具有最低的权重.(参见 http://groups.drupal.org/node/11788#comment-38332一>).如果权重最低,则分类词汇将是节点编辑表单分类部分中的第一个词汇.
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 blog node from the Series
vocabulary (e.g. CSS Tips and Techniques) as an argument to the view. For this to happen the Series
vocabulary must have the lowest weight. (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.
现在我们需要告诉我们的视图只从 My Lists
队列中获取项目.添加关系Nodequeue: Queue
.确保选择了 [x] 需要此关系
.确保选择[x] 限制为一个或多个队列
,并将My list
作为队列.
Now we need to tell our View to take items only from the My Lists
queue. Add a relationship Nodequeue: Queue
. Make sure [x] Require this relationship
is selected. Make sure [x] Limit to one or more queues
is selected with My list
as the queue.
添加参数Nodequeue:子队列引用
.确保关系是 queue
即我们上面定义的关系.此参数将是 Series
词汇表中的分类术语.此参数将导致选择正确的子队列.
Add an argument Nodequeue: Subqueue Reference
. Make sure the Relationship is queue
i.e. the relationship we defined above. This argument is going to be the taxonomy term from the Series
vocabulary. This argument will cause the correct subqueue to be selected.
添加您感兴趣的字段,例如节点:标题
.通过勾选将此字段链接到其节点
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
添加Nodequeue:Position
作为排序条件.确保排序顺序是升序并确保使用关系 queue
.
Add Nodequeue: Position
as the sort criteria. Make sure the sort order is ascending and make sure the relationship queue
is used.
在过滤器中,确保添加 Node: Type = blog
作为过滤器.
In filters, make sure you add Node: Type = blog
as your filter.
那么这个视图要做的是:
So what this view is going to do is:
- 从当前正在查看的节点中的
Series
词汇表中获取分类术语 - 将其作为参数传递给视图
display_other_blogs_in_series
- 视图将使用该参数在
My Lists
队列中选择适当的子队列 - 子队列中的项目将按照您指定的顺序一一列出
- 这将在属于特定系列的每个博客中正确显示
- Take the taxonomy term from the
Series
vocabulary in the Node that is currently being viewed - Pass that as argument to the view
display_other_blogs_in_series
- The view will use that argument to select the appropriate subqueue in the
My Lists
queue - The items in the subqueue will be listed one by one exactly in the order you have specified
- This will appear correctly in every blog that is part of a particular series
就是这样!
后记:如果您正在使用 Views 3(在撰写本文时当前处于 alpha3)并且您想要一个块(现在相关文章位于节点主体的末尾),您可以在以下内容中进行时尚:
Postscript: If you're using Views 3 (currently at alpha3 at the time of writing) and you want a block (right now the related articles come at the end of node body) you can do it in the following fashion:
- 忘记附加视图......这不是必需的
- 添加块视图.它应包含与上述
Node Content
显示说明相同的参数、关系、字段和过滤器. - 您需要稍微修改参数
Nodequeue: Subqueue Reference
的设置:在Action to take if argument is not present 下:
选择[x]提供默认参数
.选择[x] 来自 URL 的分类术语 ID
.现在确保[] 从术语页面加载默认参数
未选中,[x] 从节点页面加载默认参数,这对相关的分类块很有用.
还有[x]按词汇限制术语
并选择系列
词汇. - 确保为块命名并将其放在适当的区域中.
- Forget about views attach... its not required
- Add a block view. It should contain the same arguments, relationships, fields and filters as the instructions above for the
Node Content
display. - You need to modify the settings for the argument
Nodequeue: Subqueue Reference
just slightly: UnderAction 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 theSeries
vocabulary. - Make sure you name the block and put it in the appropriate region.
相关文章