从自定义分类父项中获取子项列表

时间:2015-02-13 作者:steamfunk

我正在尝试创建我的网站页脚部分,其中包含来自父级的术语链接li,用于我创建的自定义分类法。

function add_custom_taxonomies() {
  // Add new "producttype" taxonomy to products
  register_taxonomy(\'producttype\', \'product\', array(
    // Hierarchical taxonomy (like categories)
    \'hierarchical\' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    \'labels\' => array(
      \'name\' => _x( \'Producttypes\', \'taxonomy general name\' ),
      \'singular_name\' => _x( \'Producttype\', \'taxonomy singular name\' ),
      \'search_items\' =>  __( \'Search Producttypes\' ),
      \'all_items\' => __( \'All Producttypes\' ),
      \'parent_item\' => __( \'Parent Producttype\' ),
      \'parent_item_colon\' => __( \'Parent Producttype:\' ),
      \'edit_item\' => __( \'Edit Producttype\' ),
      \'update_item\' => __( \'Update Producttype\' ),
      \'add_new_item\' => __( \'Add New Producttype\' ),
      \'new_item_name\' => __( \'New Producttype Name\' ),
      \'menu_name\' => __( \'Product Type\' ),
    ),
    // Control the slugs used for this taxonomy
    \'rewrite\' => array(
      \'slug\' => \'Producttype\', // This controls the base slug that will display before each term
      \'with_front\' => false, // Don\'t display the category base before "/locations/"
      \'hierarchical\' => true // This will allow URL\'s like "/locations/boston/cambridge/"
    ),
  ));
}
add_action( \'init\', \'add_custom_taxonomies\', 0 );
我为分类法“producttype”创建了一个称为“Type”的父项,我只想获取父项“Type”下的那些子项,并将它们显示为链接。我在wordpress仪表板中手动创建了父术语。

1 个回复
SO网友:Taruc

get_term_children() 应该能够做到这一点。链接中的示例看起来不错。

结束

相关推荐

Get taxonomy names by post id

我试图创建一个页面,在其中一个页面上显示几个帖子。到目前为止还不错。一切正常。现在,我在foreach循环中显示帖子,检查它们是否连接到页面。我需要的是wp_get_post_terms($post->ID); 但这行不通。有custom registered_taxonomy\'s那么我怎样才能得到所有taxonomy names 通过$post->ID?