Drupal 分类块、词汇表
我正在寻找实现列出特定词汇表的所有术语的块的最佳方法。每个术语应链接到列出与该术语关联的所有节点的页面。任何帮助将不胜感激。谢谢!
I looking for the best way to implement a block that lists all terms of a certain vocabulary. Each term should link to page that lists all nodes associated with that term. Any help would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅此处的精彩教程,以准确实现您想要的
http://chrisshattuck.com/blog/how-add-block-menu-tags-or-other-taxonomy-terms-drupal-site
See here for a great tutorial to achieve exactly what you want
http://chrisshattuck.com/blog/how-add-block-menu-tags-or-other-taxonomy-terms-drupal-site
解决这个问题的最简单方法可能是使用 Views,并简单地创建一个类型为“的新视图”学期”。下面是一个简单的示例,假设您对视图 UI 有一定的了解:
值得注意的是,视图确实有一些开销,但根据我的经验,它的灵活性和易用性远远超过了相对较小的性能影响。
如果您想避免使用视图,您可以使用 hook_block() 编写一个非常简单的自定义模块并调整 http:// /drupal.org/node/247472。如果您愿意,我可以使用基于此的示例模块来编辑此答案。
The easiest way to approach this would probably be to use Views, and simply create a new view of the type "term". Here's a quick example which assumes that you have some basic familiarity with the Views UI:
It's worth noting that Views does indeed have some overhead, but in my experience, its flexibility and ease-of-use far outweigh the relatively minor performance hit.
If you'd like to avoid using Views, you could write a pretty simple custom module using hook_block() and adapting http://drupal.org/node/247472. If you'd like, I can edit this answer with an example module based on that.
(将其作为另一个答案发布,因为这是与我的第一个答案不同的方法。)
正如我上面提到的,这是另一种涉及基于 http://drupal.org/node/247472。您也可以将该代码放入选择“PHP”输入格式的自定义块中,但这通常被认为是不好的做法。
在sites/all/modules 中添加一个名为vocabulary_block 的新文件夹。自定义并添加以下两个文件:
vocabulary_block.module
vocabulary_block.info
Notes
请务必更改
$vid = 43 ;
到反映词汇表的ID
你想加载。您可以找到
访问视频
管理/内容/分类并查看
编辑的目的地
您的词汇表链接
词汇。 VID 将是最后一个
该 URL 的片段:
管理/内容/分类/编辑/词汇/[vid]。
我通常不会硬编码
$vid 到模块本身。然而,
设置必要的 Drupal
变量和管理形式(以
允许用户选择词汇
来自 Drupal 界面)将是
这个答案有点过头了。
出于您自己的文档目的,
不要忘记搜索/替换
[词汇] 在这两个文件中和
使用你自己的词汇名称
相反。
此方法不一定性能更高
比我描述的 Views 方法
早些时候,特别是当你开始考虑缓存时,
优化等
由于性能是优先考虑的,
我建议彻底测试
此页面上的各种不同方法以及
选择最适合您的方法。
(Posting this as another answer, since this is a different approach than my first answer.)
As I mentioned above, here's another approach involving a custom module based on the code at http://drupal.org/node/247472. You could also just drop that code into a custom block with the "PHP" input format selected, but that's generally considered to be bad practice.
Add a new folder in sites/all/modules called vocabulary_block. Customize and add the following two files:
vocabulary_block.module
vocabulary_block.info
Notes
Be sure to change
$vid = 43;
toreflect the ID of the vocabulary that
you'd like to load. You can find the
VID by visiting
admin/content/taxonomy and looking at
the destination of the edit
vocabulary link for your
vocabulary. The VID will be the last
fragment of that URL:
admin/content/taxonomy/edit/vocabulary/[vid].
I wouldn't normally hard-code the
$vid into the module itself. However,
setting up the necessary Drupal
variable and administration form (to
allow users to select a vocabulary
from the Drupal interface) would be
overkill for this answer.
For your own documentation purposes,
don't forget to search/replace
[vocabulary] in those two files and
use your own vocabulary's name
instead.
This method may not necessarily be more performant
than the Views method I described
earlier, especially once you start considering caching,
optimization, etc.
Since performance is a priority,
I recommend thoroughly testing a
variety of different methods on this page and
choosing whichever one is fastest for you.