有人可以帮我调整这个 php 代码吗? Drupal代码

发布于 2024-09-29 04:30:52 字数 937 浏览 1 评论 0原文

我发现这段代码可以在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖树树初阳… 2024-10-06 04:30:52

您使用 strtolower() 函数的方向是正确的,只需像这样应用它:

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

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

$term_links[] = l($term->name, 'category/' . strtolower($term->name),
没︽人懂的悲伤 2024-10-06 04:30:52

请尝试

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

它应该可以完美工作。

Please try

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

It should work perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文