簡體   English   中英

在使用層次選擇標記內容的情況下,如何僅在drupal視圖中顯示最深的分類法術語

[英]How to show only the deepest taxonomy term in a drupal view, having used hierarchical select to tag content

我有一個體育用品網站。 我使用分層選擇來標記添加到站點的產品-並且保存了沿襲術語,因此“分類法”菜單會自動創建鏈接到分類法頁面的漂亮的分層菜單-我已使用視圖對其進行了覆蓋。

參見此處的示例: http : //dayalssports.com/product-menu/badminton/rackets

球拍根據分類術語進行分組。 問題是,隨着術語譜系的保存,分類法視圖以看似隨機的順序顯示所有術語。 它不會像您期望的那樣顯示它們的parent-> Child1-> Child2等。

我只想顯示最深的術語。 因此,您不必:

球拍> Y系列球拍>羽毛球

無論如何,我還是得到了

Y系列球拍

有沒有辦法做到這一點? 還是至少有一種方法可以正確訂購它們?

順便說一句-術語之間的>字符不是默認的分隔符,我只是將其設置為該字符,因為我認為這些術語將按順序顯示。 因為它們不是,所以看起來有點愚蠢,因為它給人以層次結構的印象。 層次實際上是

羽毛球>球拍> Y系列球拍

嘗試這個:

function theme_hs_taxonomy_formatter_lineage($variables) {
  $output = '';
  $lineage = $variables['lineage'];
  $separator = theme('hierarchical_select_item_separator');

  // Render each item within a lineage.
  $items = array();
  foreach ($lineage as $level => $item ) {
    dpm($item);
    $line  = '<span class="lineage-item lineage-item-level-' . $level . '">';
    $line .= drupal_render($item);
    //this adds a flag link to every term, not just the last term
    if(!count(taxonomy_get_children($item['#options']['entity']->tid))){
      $line .= flag_create_link('hobbies_and_interests', $item['#options']['entity']->tid);
    }

    $line .= '</span>';
    $items[] = $line;
  }
  $output .= implode($separator, $items);
  return $output;
}

參考: https : //drupal.stackexchange.com/questions/58691/how-can-i-show-a-flag-link-only-for-the-deepest-terms-for-a-field-with-multipl

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM