Drupal 7 中的自定义分类术语页面
我正在尝试在 Drupal 7 中制作自定义分类术语页面。我在模板文件夹中创建了一个 page--taxonomy.tpl.php 文件。该文件仅打印出一条消息。我现在尝试通过添加
function template_preprocess_page($variables) {
if (arg(0) == 'taxonomy') {
$variables['template_file'] = 'page--taxonomy-tpl';
}
}
template.php 来强制模板文件,但它不起作用。你能帮助我吗?如果我让自定义页面正常工作,我如何获取带有该术语的节点(在页面--taxonomy.tpl.php中)?提前致谢。
I'm trying to make a custom Taxonomy Term page in Drupal 7. I've created a page--taxonomy.tpl.php file in my templates folder. The file only prints out a message. I now try to force the template file by adding
function template_preprocess_page($variables) {
if (arg(0) == 'taxonomy') {
$variables['template_file'] = 'page--taxonomy-tpl';
}
}
in my template.php, but it won't work. Can you help me? And if I get the custom page working, how do I fetch the nodes with this term (in page--taxonomy.tpl.php)? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试在 template.php 中使用它:
$variables
,因此添加一个 & 之前,template_file
更改为theme_hook_suggestions
-tpl
除非您希望它成为文件名的一部分,例如“page--taxonomy-tpl.tpl.php”,我认为这不是您想要的。有关更多信息,请查看 template_preprocess_page(), theme_get_suggestions() 和使用模板建议
Try using this in your template.php:
$variables
by reference, so add a & before ittemplate_file
has changed totheme_hook_suggestions
in Drupal 7-tpl
in the template suggestion unless you want it to be a part of the filename like "page--taxonomy-tpl.tpl.php" which I don't think is what you want.For more information, check out template_preprocess_page(), theme_get_suggestions() and Working with template suggestions
不确定这是否满足您的要求,但默认的 D7 视图之一 - 分类术语 - 模拟 Drupal 核心对分类/术语页面的处理。您可以启用它(它会自动替换 Drupal 的核心分类 URL),然后用它做任何您想做的事情,保留原始页面结构、所有块等,使用视图的页面模板(请参阅“高级”中的“主题信息”)以及所有其他花里胡哨的东西......
Not sure if this would meet your requirements, but one of default D7 views - Taxonomy term - emulates Drupal core's handling of taxonomy/term pages. You could just enable it (it would automatically replace Drupal's core taxonomy URLs), and then do whatever you want with it, keeping original page structure, all blocks etc, using Views' page templates (see "Theming information" in "Advanced") and all other bells and whistles...
由于您使用的是Drupal 7,因此您还可以创建一个文件名“taxnomy-term.tpl.php”并根据您的需要进行编辑。
请参阅taxonomy-term.tpl.php
Since you are using Drupal 7, you could also create a file name "taxnomy-term.tpl.php" and edit according to your needs.
See taxonomy-term.tpl.php
可以使用 hook_menu_alter() 获得对分类术语页面的完全控制。参见https://drupal.stackexchange.com/questions/48420/主题和覆盖分类术语词汇页/111194#111194
Full control over the taxonomy term page can be obtained using hook_menu_alter() . See https://drupal.stackexchange.com/questions/48420/theming-and-overriding-taxonomy-term-vocabulary-page/111194#111194