承接 ayctor/cpt 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ayctor/cpt

Composer 安装命令:

composer require ayctor/cpt

包简介

Allow you to generate easily some cutom post types for WordPress

README 文档

README

Introduction

The goal of this package is to facilitate the making of Custom Post Type (CPT) within wordpress.

Get Started

First install it with composer

composer require ayctor/cpt

Create a Class for the New CPT

use CustomPostType\Model;

class Example extends Model
{
}

Declare your new class in function.php

new CustomPostType\Admin; // required for assets registration
new Example;

Example of fields

// name of your post type
protected $internal_name = 'example';

// generate labels, you can also use protected $labels
protected $name = 'Examples';

// list of args for register_post_type()
protected $cpt_args = [
    'public' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'query_var' => true,
    'capability_type' => 'post',
    'has_archive' => false,
    'hierarchical' => false,
    'menu_icon' => 'dashicons-carrot',
    'rewrite' => true,
    'menu_position' => null,
    'supports' => array( 'title', 'editor', 'excerpt' )
];

// list of args for register_taxonomy()
protected $taxonomies = [
    'carrot_cat' => [
        'label' => 'Country',
        'hierarchical' => true,
        'rewrite' => ['slug' => '/country']
    ],
    'carrot_tag' => [
        'label' => 'Colors',
        'hierarchical' => false,
        'rewrite' => ['slug' => '/colors']
    ]
];


// Load all data to CPT editor page
public function adminEditor()
{
     // Add meta box
    $this->metaBox('ay-carrot-meta', 'Carrots');

    // Add fields
    $this->label('Information', 'carrot_info', 'ay-carrot-meta');
    $this->info('carrot_info', 'ay-carrot-meta');

    $this->label('Text', 'carrot_text', 'ay-carrot-meta');
    $this->text('carrot_text', 'ay-carrot-meta');

    $this->label('Text multiple', 'carrot_text_multiple', 'ay-carrot-meta');
    $this->text('carrot_text_multiple', 'ay-carrot-meta', ['multiple' => true]);

    $this->label('Text Disabled', 'carrot_disabled', 'ay-carrot-meta');
    $this->text('carrot_disabled', 'ay-carrot-meta', ['attributes' => ['disabled' => 'disabled']]);

    $this->label('Number', 'carrot_number', 'ay-carrot-meta');
    $this->number('carrot_number', 'ay-carrot-meta');

    $this->label('Date', 'carrot_date', 'ay-carrot-meta');
    $this->date('carrot_date', 'ay-carrot-meta');

    $this->label('Time', 'carrot_time', 'ay-carrot-meta');
    $this->time('carrot_time', 'ay-carrot-meta');

    $this->label('File', 'carrot_file', 'ay-carrot-meta');
    $this->file('carrot_file', 'ay-carrot-meta');

    $this->label('File multiple', 'carrot_file_multiple', 'ay-carrot-meta');
    $this->file('carrot_file_multiple', 'ay-carrot-meta', ['multiple' => true]);

    $this->label('Textarea', 'carrot_textarea', 'ay-carrot-meta');
    $this->textarea('carrot_textarea', 'ay-carrot-meta');

    $this->label('Textarea disabled', 'carrot_textarea_disabled', 'ay-carrot-meta');
    $this->textarea('carrot_textarea_disabled', 'ay-carrot-meta', ['attributes' => ['disabled' => 'disabled']]);

    $this->label('Select', 'carrot_select', 'ay-carrot-meta');
    $this->select('carrot_select', 'ay-carrot-meta', ['options' => ['are' => 'yes', 'eest' => 'testons']]);

    $this->label('Select multiple', 'carrot_select_multiple', 'ay-carrot-meta');
    $this->select('carrot_select_multiple', 'ay-carrot-meta', ['multiple' => true, 'options' => ['are' => 'yes', 'test' => 'no']]);

    $this->label('Radio', 'carrot_radio', 'ay-carrot-meta');
    $this->radio('carrot_radio', 'ay-carrot-meta', ['options' => ['areyou' => 'yes', 'ares' => 'se y'], 'inline' => false]);

    $this->label('Checkbox', 'carrot_checkbox', 'ay-carrot-meta');
    $this->checkbox('carrot_checkbox', 'ay-carrot-meta', ['options' => ['areyou' => 'yes', 'ares' => 'se y']]);

    $this->editor('carrot_editor', 'ay-carrot-meta');

    $this->label('Image', 'carrot_image', 'ay-carrot-meta');
    $this->image('carrot_image', 'ay-carrot-meta');

    $this->label('Gallery', 'carrot_gallery', 'ay-carrot-meta');
    $this->image('carrot_gallery', 'ay-carrot-meta', ['gallery' => true]);

    $this->label('CPT', 'carrot_cpt', 'ay-carrot-meta');
    $this->cpt('carrot_cpt', 'ay-carrot-meta', ['args' => ['post_type' => 'image']]);

    $this->label('CPT Multiple', 'carrot_cpt_multiple', 'ay-carrot-meta');
    $this->cpt('carrot_cpt_multiple', 'ay-carrot-meta', ['multiple' => true]);

    // Custom columns
    $this->column('cb', '<input type="checkbox" />', true);
    $this->column('title', 'Title', true);
    $this->column('carrot_thumb', 'Thumbnail', false, 'thumbnail');
    $this->column('carrot_time', 'Time', true, 'meta');
    $this->column('carrot_cat', 'Country', false, 'term');
    $this->column('carrot_tag', 'Colors', false, 'term');
    $this->column('carrot_custom', 'Custom', false, 'custom', 'My custom value');
    $this->column('date', 'Date', true);

    // Custom filters
    $this->filter('carrot_radio', array( '' => 'Carrot radio test', 'yes' => 'Yes', 'no' => 'No' ));
    $this->filter('test', array( '' => 'test', 'yes' => 'Yes', 'no' => 'No'));
}

Usefuls links

List of args for register_post_type : https://codex.wordpress.org/Function_Reference/register_post_type

List of args for register_taxonomy : https://codex.wordpress.org/Function_Reference/register_taxonomy

统计信息

  • 总下载量: 3.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固