wordpress - 重新使用自定义帖子类型的默认类别/标签分类法?

标签 wordpress wordpress-theming custom-post-type taxonomy

在我的 WordPress 主题的 functions.php 中,我创建了一个名为 foobar 的自定义帖子类型。

是否可以重新使用 foobar 帖子的默认类别和标签?或者我是否必须创建两个分类法:

  • 一个类别
  • 另一个用于标签

要实现这个目标吗?

编辑:我想我已经通过在创建自定义帖子类型的函数中使用此代码解决了这个问题:

register_taxonomy_for_object_type('category', 'foobar');
register_taxonomy_for_object_type('post_tag', 'foobar');

最佳答案

registering the post type 时,您可以用一 block 石头杀死两只鸟并使用taxonomies 键。 :

$product_labels = array(
        'name' => _x('Products', 'post type general name'),
        'singular_name' => _x('Product', 'post type singular name'),
        'add_new' => _x('Add New', 'portfolio item'),
        'add_new_item' => __('Add New Product'),
        'edit_item' => __('Edit Product'),
        'new_item' => __('New Product'),
        'view_item' => __('View Product'),
        'search_items' => __('Search Products'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );
    $product_args = array(
        'labels' => $product_labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array('slug' => 'product'),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => 2,
        'supports' => array('title','editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions', 'page-attributes', 'custom-fields', ),
        // Set the available taxonomies here
        'taxonomies' => array('category', 'post_tag') 
    );
    register_post_type('product', $product_args);

关于wordpress - 重新使用自定义帖子类型的默认类别/标签分类法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6258996/

相关文章:

javascript - 如何在 WordPress 主题中包含 jQuery?

php - 在 wordpress 中使用 wp_get_attachment_image() 的正确方法

wordpress - 如何在自定义帖子类型循环中将帖子标签添加为类?

css - 流体网格布局控制

php - 谷歌爬取mysql数据库

javascript - 在 Wordpress 中包含 Fullpage.js(或一般的 JS)

php - WordPress 自定义帖子类型存档-<帖子类型>.php 不工作

css - 无法单击任何链接,因为 wordpress 中的元素覆盖了它们

javascript - 根据内容更改元素的颜色

ajax - 使用分类法过滤自定义帖子 - 添加全部按钮