当前位置:  开发笔记 > 编程语言 > 正文

如何为自定义帖子类型制作自定义页面

如何解决《如何为自定义帖子类型制作自定义页面》经验,为你挑选了0个好方法。

所以我使用以下代码为我的wordpress网站制作了一个自定义帖子类型:

add_action( 'init', 'register_cpt_bingo' );

function register_cpt_bingo() {

    $labels = array( 
        'name' => _x( 'Bingo Sites', 'bingo' ),
        'singular_name' => _x( 'Bingo', 'bingo' ),
        'add_new' => _x( 'Add New', 'bingo' ),
        'add_new_item' => _x( 'Add New Bingo Site', 'bingo' ),
        'edit_item' => _x( 'Edit Bingo', 'bingo' ),
        'new_item' => _x( 'New Bingo', 'bingo' ),
        'view_item' => _x( 'View Bingo Site', 'bingo' ),
        'search_items' => _x( 'Search Bingo Sites', 'bingo' ),
        'not_found' => _x( 'No bingo sites found', 'bingo' ),
        'not_found_in_trash' => _x( 'No bingo sites found in Trash', 'bingo' ),
        'parent_item_colon' => _x( 'Parent Bingo:', 'bingo' ),
        'menu_name' => _x( 'Bingo Sites', 'bingo' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => true,

        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),

        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,

        'menu_icon' => '/wp-content/themes/gamblingq/img/bingo.png',
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'page'
    );

    register_post_type( 'bingo', $args );
}

它完美地运作.这是我的管理面板中的一个屏幕:

在此输入图像描述

如何添加选项以选择自定义页面模板,如下图所示:

在此输入图像描述

任何建议都有帮助!谢谢!

推荐阅读
pan2502851807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有