【问题标题】:Relationship among different taxonomy terms in wordpresswordpress中不同分类术语之间的关系
【发布时间】:2014-06-12 06:07:07
【问题描述】:

我在我的 wordpress 主题中定义了四个不同的分类术语,它们是

  • 大陆
  • 国家/地区
  • 国家
  • 城市

我的问题是我无法弄清楚如何让用户根据不同的分类来指定父子关系。 例如,如果用户在大洲下添加“亚洲”,在国家下添加“印度”,在州下添加“德里”,在城市下添加“新德里”,如何将印度指定为亚洲的孩子,德里作为印度的孩子,新德里作为孩子德里的 请帮我。谢谢。

自定义分类的代码是这样的: `

add_action('init', 'register_my_taxes_states');

function register_my_taxes_states() {


 register_taxonomy( 'states',

array (
          0 => 'schools',
          1 => 'universities',
          2 => 'institutes',
          3 => 'colleges',
        ),
    array( 'hierarchical' => true,
        'label' => 'states',
        'show_ui' => true,
        'query_var' => true,
        'show_admin_column' => false,
        'labels' => array (
      'search_items' => 'state',
      'popular_items' => '',
      'all_items' => '',
      'parent_item' => '',
      'parent_item_colon' => '',
      'edit_item' => '',
      'update_item' => '',
      'add_new_item' => '',
      'new_item_name' => '',
      'separate_items_with_commas' => '',
      'add_or_remove_items' => '',
      'choose_from_most_used' => '',
    )
) ); 
}

`

【问题讨论】:

    标签: wordpress custom-taxonomy


    【解决方案1】:

    我从未使用单独的分类法创建过这样的关系。我能想到的使用分类法最简单的解决方案是只创建一个分类法,然后使用内置的父/子功能。

    我个人不喜欢在大多数情况下使用分类法。我发现我遇到了您在人际关系方面面临的问题,而我的客户似乎并不觉得它很直观。我更喜欢通过使用自定义帖子类型而不是分类法来做到这一点。根据您上面的描述,这就是我要做的。

    1. 创建 4 种自定义帖子类型(大陆、国家、州、城市)http://codex.wordpress.org/Post_Types
    2. 下载/安装插件“Posts to Posts”,它将创建一个 不同帖子类型之间的关系https://wordpress.org/plugins/posts-to-posts/
    3. 在“Continent & Country”、“Country & State”、“State & City”之间注册连接类型。 https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage

    然后,您可能希望根据上面的代码创建“城市与学校”之间的关系。这样,您可以进入并选择学校所在的城市,您还将获得州、国家和大陆的数据。

    希望这会有所帮助。

    【讨论】:

    • 非常感谢,您为我指明了正确的方向。
    猜你喜欢
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 2022-01-06
    • 1970-01-01
    相关资源
    最近更新 更多