【问题标题】:A function to separate taxonomy terms分离分类术语的功能
【发布时间】:2011-03-17 12:20:11
【问题描述】:
 function garland_separate_terms($node_taxonomy) {
   if ($node_taxonomy) {

foreach ($node_taxonomy AS $term) {
 $links[$term->vid]['taxonomy_term_'. $term->tid] = array(
   'title' => $term->name, 
  'href' => taxonomy_term_path($term),
'attributes' => array(
   'rel' => 'tag',
   'title' => strip_tags($term->description)
   ),
 );
}
   //theming terms out
     foreach ($links AS $key => $vid) {
 $terms[$key] = theme_links($vid);
   }
  }
      return $terms;
    }

这个函数我不是很懂。

  1. 为什么作者没有将 $node_taxonomy 声明为数组($node_taxonomy=array())
  2. 这个$links[$term->vid]['taxonomy_term_'. $term->tid] 来自哪里?

【问题讨论】:

    标签: drupal drupal-6 taxonomy


    【解决方案1】:

    他希望$node_taxonomy 包含特定节点的所有术语。 Each term is an object that contains attributes like vid,tid,name,description and path.

    $links 是他正在创建的一个新数组。

    因此,基本上,如果一个特定节点具有词汇 a 中的术语 a1、a2、a3 和词汇 b 中的术语 b1、b2,那么数组会将其存储为

    $links[a][a1] = details of a1 to convert into link
    
    $links[a][a2] = details of a2 to convert into link
    
    $links[a][a3] = details of a3 to convert into link
    
    $links[b][b1] = details of b1 to convert into link
    
    $links[b][b2] = details of b2 to convert into link
    

    最后,他使用 theme_links() 函数为 $links 的每个元素设置主题。

    所以最后你会得到一个所有术语的列表,作为按词汇分组的链接。

    【讨论】:

    • 谢谢!你怎么知道 term 是一个对象?$links 是他正在创建的一个新数组。 $links=array() 使用前是否需要声明
    • 基本上,返回术语的drupal函数将它们作为对象返回。关于 $links = array(),它不是必需的,但它是一个很好的编程习惯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多