在Wordpress中为自定义帖子类型制作孩子?

时间:2015-06-23 10:20:11

标签: php wordpress custom-post-type

我需要帮助! 我已经在我的主题中创建了一个自定义帖子类型,并且它有效。结果如下:

  • mysitename.co/collage/harvard

我想要添加新的孩子,我的意思是这样:

  • mysitename.co/collage/harvard/address

  • mysitename.co/collage/harvard/students

从上面的地址和学生"是来自哈佛的孩子。

我目前的代码是:

add_action('init', 'register_segala_Collage');

function register_all_list_Collage() {

    $labels = array( 
        'name' => _x('Collage', 'newborne'),
        'singular_name' => _x('Collage', 'newborne'),
        'all_items' => _x('All Collage', 'newborne'),
        'add_new' => _x('Add List Collage', 'newborne'),
        'add_new_item' => _x('Add List Collage', 'newborne'),
        'edit' => _x('Edit List Collage', 'newborne'),
        'edit_item' => _x('Edit List Collage', 'newborne'),
        'new_item' => _x('New Collage', 'newborne'),
        'view' => _x('View Collage', 'newborne'),
        'view_item' => _x('View Collage', 'newborne'),
        'search_items' => _x('Search Collage', 'newborne'),
        'not_found' => _x('No Collage Found', 'newborne'),
        'not_found_in_trash' => _x('No Collage Found', 'newborne'),
        'menu_name' => _x( 'Collage', 'newborne' ),
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'capability_type' => 'post',
        'rewrite' => array( 'slug' => 'Collage' ),
        'query_var' => true,
        'exclude_from_search' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-nametag',
        'supports' => array('title', 'editor', 'thumbnail')
    );
    register_post_type( 'Collage', $args );
}

我该怎么做?有代码吗? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

您可以尝试hierarchical自定义帖子类型。 register_post_type获取hierarchicaltrue false参数。默认值为false,表示非分层自定义帖子类型。

查看官方文档: https://codex.wordpress.org/Function_Reference/register_post_type

注意:

请阅读codex页面中的Note。如果您要发布大量帖子,那么您可能会遇到性能问题。