dousha7904 2015-06-23 10:20
浏览 68
已采纳

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

I need help! I have create a custom post type in my theme and it worked. It has result:

  • mysitename.co/collage/harvard

I want new childs that can be added, I mean like this:

  • mysitename.co/collage/harvard/address

  • mysitename.co/collage/harvard/students

from above where the "address and students" is child from harvard.

My current code is:

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 );
}

How can I do that? is there any code? Thanks in help.

  • 写回答

1条回答 默认 最新

  • doulang9521 2015-06-24 03:59
    关注

    May be you should try hierarchical Custom Post Type. register_post_type takes hierarchical parameter which is either true or false. Default value is false, that means non-hierarchical custom post type.

    Check official documentation: https://codex.wordpress.org/Function_Reference/register_post_type

    Note:

    Please read the Note in the codex page. If you are going to have large number of posts then you might caught in performance issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题