2014-09-19 42 views
0

我是wordpress新手。我想要在頁腳中顯示聯繫表單,並且以這種形式,我希望將類別的下拉列表顯示爲我的投資組合的類別。在wordpress中獲取所有類別的投資組合

如何獲取所有投資組合類別名稱?

有人可以回答我。

在此先感謝。

+1

http://codex.wordpress.org/Function_Reference/get_categories將是一個很好的起點。你試過什麼了? – JakeSteam 2014-09-19 10:24:34

+0

這可能會幫助你http://stackoverflow.com/questions/20196719/wordpress-get-category-names-for-a-custom-post-type – 2014-09-19 10:30:54

回答

1

在WP中,類別(組)是分類法,分類法由術語(單個類別)組成。

以下代碼收集所有投資組合類別並填充陣列,以便您可以將其用於<select>

$select_category_arr = array(); 
    $taxonomy = 'portfolio_category'; // Go to WPadmin -> Portfolio categories. Check url for correct taxonomy name. 
    $terms = get_terms($taxonomy); // Get all terms of a taxonomy 
    if ($terms && !is_wp_error($terms)) { 
     foreach($terms as $term) { 
      $select_category_arr[$term->slug] = $term->name;  
     } 
    } 

數組$select_category_arr包含所有投資組合類別。

最好的問候,

比約恩

相關問題