开发者

Could someone please tweak this php code for me? Drupal code

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 phptempla开发者_如何学JAVAte_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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜