wordpress自定义文章

本文介绍如何使用PHP在WordPress中自定义注册产品和案例两种文章类型,并设置了相应的标签、菜单位置及支持特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//产品
function customer_post_product() {
    $post_type = 'product';
    $labels = [
        'name' => '产品',
        'singular_name' => '产品',
        'add_new' => '添加产品',
        'add_new_item' => '添加新产品',
        'edit' => '修改产品',
        'edit_item' => '修改产品',
        'new_item' => '新产品',
        'all_items' => '所有产品',
        'view' => '查看产品',
        'view_item' => '查看产品',
        'search_items' => '搜索产品',
        'not_found' => '没有该产品',
        'not_found_in_trash' => '没有回收该产品',
        'parent_item_colon' => '',
        'menu_name' => '产品'
    ];
    $args = [
        'public' => true,
        'menu_position' => 15,
        'supports' => ['title', 'editor', 'comments', 'thumbnail'],
        'has_archive' => true
    ];
    customer_post_seeting( $post_type, $labels, $args );
}
 //案例
function customer_post_case() {
    $post_type = 'case';
    $labels = [
        'name' => '案例',
        'singular_name' => '案例',
        'add_new' => '添加案例',
        'add_new_item' => '添加新案例',
        'edit' => '修改案例',
        'edit_item' => '修改案例',
        'new_item' => '新案例',
        'all_items' => '所有案例',
        'view' => '查看案例',
        'view_item' => '查看案例',
        'search_items' => '搜索案例',
        'not_found' => '没有该案例',
        'not_found_in_trash' => '没有回收该案例',
        'parent_item_colon' => '',
        'menu_name' => '案例'
    ];
    $args = [
        'public' => true,
        'menu_position' => 16,
        'supports' => ['title', 'editor', 'comments', 'thumbnail'],
        'has_archive' => true
    ];
    customer_post_seeting( $post_type, $labels, $args );
}

add_action( 'init', 'customer_post_product' );
add_action( 'init', 'customer_post_case' );

 function customer_post_seeting( $post_type, $labels, $args ) {
    register_post_type( 
        $post_type,
        seeting_post_args($labels, $args)
    );
 }

 function seeting_post_labels($labels) {
    $labels_arr = [
        'name'               => $labels['name'],
        'singular_name'      => $labels['singular_name'],
        'add_new'            => $labels['add_new'],
        'add_new_item'       => $labels['add_new_item'],
        'edit_item'          => $labels['edit_item'],
        'new_item'           => $labels['new_item'],
        'all_items'          => $labels['all_items'],
        'view'               => $labels['view'],
        'view_item'          => $labels['view_item'],
        'search_items'       => $labels['search_items'],
        'not_found'          => $labels['not_found'],
        'not_found_in_trash' => $labels['not_found_in_trash'],
        'parent_item_colon'  => $labels['parent_item_colon'],
        'menu_name'          => $labels['menu_name'],
    ];
    return $labels_arr;
 }

 function seeting_post_args($labels, $args) {
    $args_arr = [
        'labels'        => seeting_post_labels($labels),
        'public'        => $args['public'],
        'menu_position' => $args['menu_position'],
        'supports'      => $args['supports'],
        'has_archive'   => $args['has_archive'],
    ];
    return $args_arr;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值