我有很少的節點類型,其中一些有一個額外的字段鏈接到分類詞彙表。我如何獲得分類詞彙表id或名稱,如果我知道該字段存在的字段名稱和節點類型?我如何通過node_type得到分類詞彙表
1
A
回答
2
在Drupal 7的字段可以被添加到任何實體/束,以及用於長期參考領域中使用的詞彙表上的實體/束水平設置現場級,不。
因此,您不需要查詢特定內容類型的字段設置,而只需查詢字段本身的設置。詞彙機器名稱都存儲在settings
陣列的allowed_values
重點從field_info_field()
返回:
$field_name = 'field_name_of_field';
$info = field_info_field($field_name);
$vocab_keys = array();
foreach ($info['settings']['allowed_values'] as $item) {
$vocab_keys[] = $item['vocabulary'];
}
// $vocab_keys now contains an array of all vocabulary machine names allowed on this field
希望幫助
0
如果您在額外領域中保留術語,此代碼很有用。
/**
* Get vocabulary ID by term name applied to node
*/
$tid = $node->your_field[$node->language][0]['tid'];
$term = taxonomy_term_load($tid);
/* $term now is the following object
stdClass Object(
[tid] => 1
[vid] => 1
[name] => Name of term
[description] => Description of term
[format] => full_html
[weight] => 0
[vocabulary_machine_name] => vocabulary
) */
/**
* Loading vocabularies
*/
$vocabularies = taxonomy_get_vocabularies();
/* $vocabularies now is the following array
Array(
[1] => stdClass Object(
[vid] => 1
[name] => Forums
[machine_name] => forums
[description] => Forum navigation vocabulary
[hierarchy] => 1
[module] => forum
[weight] => -10
)
[2] => stdClass Object(
[vid] => 2
[name] => Category
[machine_name] => category
[description] =>
[hierarchy] => 1
[module] => taxonomy
[weight] => -9
)
) */
/**
* Vocabulary searched by you
*/
$vocabulary = $vocabularies[$term->vid];
/* $vocabulary now is the following object
Array(
[1] => stdClass Object(
[vid] => 1
[name] => Forums
[machine_name] => forums
[description] => Forum navigation vocabulary
[hierarchy] => 1
[module] => forum
[weight] => -10
)
) */
相關問題
- 1. 通過名稱獲得詞彙表
- 2. 通過網絡管理Plone詞彙表
- 3. Drupal分類標準塊,詞彙表
- 4. Drupal6x:來自同一分類詞彙表
- 5. 空的詞彙通過CountVectorizer
- 6. Drupal:從分類詞彙詞彙創建分層菜單
- 7. 如何檢查分類詞彙表何時更改Drupal 7
- 8. 如何通過日期獲得匯率?
- 9. 如何從兩個詞彙表生成Drupal分類標準Breadcrumbs?
- 10. 過濾詞彙表視圖
- 11. 詞彙表的詞法分析
- 12. 通過小型詞彙進行詞彙封閉?
- 13. 如何通過TF/IDF得分獲得文檔中的單詞列表
- 14. drupal 7 - 按分類詞彙分組
- 15. 如何分解冗長的詞彙,但忽略短詞彙?
- 16. 潛在迪裏克萊特分配如何處理詞彙不在詞彙表
- 17. 如何通過分組得到年齡分佈列表
- 18. 如何通過jquery得到父類型
- 19. 我如何得到這個:通過?
- 20. 如何使用JAWS插件獲得wordNet詞彙類別(名詞類別和動詞類別)
- 21. PHP如何區分上下文中的詞彙類型
- 22. 通過彙總到HTML表中的多級分組
- 23. 設置詞彙列表的PHP OO類
- 24. 如何建立一個詞彙表
- 25. 如何處理deezer ID詞彙表
- 26. 如何在給定單詞的單詞袋詞彙中獲得單詞的id?
- 27. 通過API以其他語言進行詞彙表
- 28. 如何通過單詞列表增加?
- 29. 如何通過謂詞LINQ表達
- 30. 如何使用視圖在Drupal 7上顯示2級分類詞彙列表
酷! Thx共享關於'field_info_field'函數=) – 2011-12-23 16:20:24
@ VladStratulat:沒問題:)如果你有興趣,可以在'/ modules/field/field.info.inc'中找到大量有用的字段信息函數 – Clive 2011-12-23 16:24:38
優秀的解決方案,thnx ! – 2011-12-24 20:47:00