有人可以帮我调整这个 php 代码吗? Drupal代码
我发现这段代码可以在我的 Drupal 站点上运行。它以逗号分隔的列表输出分类术语。 它成功地构建了我的分类列表,如下所示:
商业、娱乐、休闲
虽然这很棒,但它使用相同的名称在网址中链接自身,所以我得到:
www.yourdomain .com/category/Business
如何仅将网址中的术语名称设为小写以获得这样的结果?
www.yourdomain.com/category/business
我相信我必须使用这个: string strtolower ( string $str ) 但我不太懂 php。那么我从哪里开始呢?
function phptemplate_preprocess_node(&$vars) {
// Taxonomy hook to show comma separated terms
if (module_exists('taxonomy')) {
$term_links = array();
foreach ($vars['node']->taxonomy as $term) {
$term_links[] = l($term->name, 'category/' . $term->name,
array(
'attributes' => array(
'title' => $term->description
)));
}
$vars['node_terms'] = implode(', ', $term_links);
}
}
感谢您的帮助!
I found this code to work on my Drupal site. It outputs the taxonomy terms in a comma separated list.
It successfully builds my taxonomy list to look like this:
Business, Entertainment, Leisure
While that's great, its using the same names to link itself in the url and so I get this:
www.yourdomain.com/category/Business
How can I make only the term name in the url lowercase to get it like this?
www.yourdomain.com/category/business
I believe I have to use this: string strtolower ( string $str ) but I'm not very php savvy. So where do I start?
function phptemplate_preprocess_node(&$vars) {
// Taxonomy hook to show comma separated terms
if (module_exists('taxonomy')) {
$term_links = array();
foreach ($vars['node']->taxonomy as $term) {
$term_links[] = l($term->name, 'category/' . $term->name,
array(
'attributes' => array(
'title' => $term->description
)));
}
$vars['node_terms'] = implode(', ', $term_links);
}
}
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用
strtolower()
函数的方向是正确的,只需像这样应用它:You're on the right track with the
strtolower()
function, just apply it like so:请尝试
它应该可以完美工作。
Please try
It should work perfectly.