开发者

A function to separate taxonomy terms

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

I can't understand this function very well.

  1. why the author doesn't declare the $node_开发者_如何学运维taxonomy as an array ($node_taxonomy=array()).
  2. where this $links[$term->vid]['taxonomy_term_'. $term->tid] come from?


He expects $node_taxonomy to contain all the terms of a particular node. Each term is an object that contains attributes like vid,tid,name,description and path.

$links is a new array that he is creating.

So basically if a particualr node has terms a1,a2,a3 from vocabulary a and terms b1,b2 from vocabulary b then the array will store it as

$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

Finally he is theming the each element of $links using the theme_links() function.

So finally you get a list of all terms as links that are grouped by vocabularies.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜