有人可以为我调整这个PHP代码吗? Drupal代码

问题描述:

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!

我发现此代码可以在我的Drupal站点上运行。 它以逗号分隔的列表输出分类术语。 它成功构建了我的分类列表,如下所示: p>

商业,娱乐,休闲 strong> p>

虽然这很棒,但它使用相同的名称在网址中链接自己,所以我得到了这个: p>

www.yourdomain.com/category/ 业务 strong> p>

如何才能使用url小写字母中的术语名称来实现这一目标? p>

www。 yourdomain.com/category/business

nn

我相信我必须使用它:string strtolower(string $ str)但我不是很精通php。 那么我从哪里开始呢? p>

  function phptemplate_preprocess_node(& $ vars){
 
 //分类钩子以显示逗号分隔的术语
 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); 
} 
 
} 
  code>  pre> 
 
 

感谢您的帮助! p> div>

You're on the right track with the strtolower() function, just apply it like so:

$term_links[] = l($term->name, 'category/' . strtolower($term->name),

Please try

$term_links[] = l($term->name, 'category/' . strtolower($term->name),

It should work perfectly.