【问题标题】:Could someone please tweak this php code for me? Drupal code有人可以为我调整这个 php 代码吗? Drupal 代码
【发布时间】:2011-04-29 10:12:15
【问题描述】:

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

商务、娱乐、休闲

虽然这很好,但它使用相同的名称在 url 中链接自身,所以我明白了:

www.yourdomain.com/category/Business

如何仅将 url 中的术语名称设为小写以得到这样的结果?

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);
      }

}

感谢您的帮助!

【问题讨论】:

    标签: php drupal taxonomy lowercase


    【解决方案1】:

    请尝试

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

    它应该可以完美运行。

    【讨论】:

      【解决方案2】:

      strtolower() 函数让你走在正确的轨道上,只需像这样应用它:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-06
        • 1970-01-01
        • 2015-10-28
        • 2016-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多