Drupal 6 中的主题节点链接
默认情况下,博客页面中的节点链接包含 blog_usernames_blog
(管理员的博客)、comment_add
(添加新评论)和 node_read_more
(阅读更多) 。
我需要删除前两个,并更改 node_read_more 中的文本。
我在主题中的 template.php 中创建了一个名为 $themenamepreprocess_node
的函数,其内容如下:
function mytheme_preprocess_node(&$vars, $hook){
$node = $vars['node'];
//blog node, not in full node page
if($vars['node']->type == 'blog' AND !$vars['page']){
$vars['node']->links['node_read_more']['title'] = t('My custom read more here');
unset($vars['node']->links['blog_usernames_blog']);
unset($vars['node']->links['comment_add']);
}
//debug:
echo "<!-- DEBUG\n";
print_r($vars['node']->links);
echo "\n-->";
}
但它不起作用;当我在函数末尾打印 $vars['node']->links
时,链接数组正是我想要的;但是当呈现页面时,会显示旧的默认链接。
为什么? 如何使用主题功能仅针对某些内容类型且仅在节点列表页面中对节点链接进行主题化?
PS:我在每次尝试之前都清除了缓存和主题注册表;)
By default, the node links in the blog page contains blog_usernames_blog
(admin's blog), comment_add
(Add new comment) and node_read_more
(Read more).
I need to get rid of the first 2 of them, and to change the text in node_read_more.
I created a function named $themenamepreprocess_node
into template.php in my theme, with this content:
function mytheme_preprocess_node(&$vars, $hook){
$node = $vars['node'];
//blog node, not in full node page
if($vars['node']->type == 'blog' AND !$vars['page']){
$vars['node']->links['node_read_more']['title'] = t('My custom read more here');
unset($vars['node']->links['blog_usernames_blog']);
unset($vars['node']->links['comment_add']);
}
//debug:
echo "<!-- DEBUG\n";
print_r($vars['node']->links);
echo "\n-->";
}
But it doesnt work; when i print the $vars['node']->links
in the end of the functions, the links array is exactly as i want it; but when the page is rendered, the old default links are showed.
Why?
How can i theme the node links just for some content-type and only in the node list page, with theming functions?
p.s: i cleared the cache and the theme registry before every try ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先:你应该在 $hook 上进行测试,否则这个预处理函数将在每个地方被调用。即使您在大型服务器上运行小型网站,它也会导致您的网站瘫痪。
第二:如果 print_r 打印出正确的链接,那么可以肯定代码 /is/ 已运行,无需担心主题注册表。
现在,您可能正在寻找错误的主题挂钩。 theme_links 就是您想要的。 http://api.drupal.org/api/function/theme_links/5
First: you should test on $hook, else this preprocess function will be called on each and every place. It will bring your site down, even if you run a small site on a large server.
Second: if the print_r, prints the correct links, then for sure the code /is/ ran, no need to worry about the theme registry.
Now, you probably are looking at the wrong theme-hook. theme_links is what you will want. http://api.drupal.org/api/function/theme_links/5