Title: SuperCPT
Author: Matthew Boynes
Published: <strong>2013 年 2 月 10 日</strong>
Last modified: 2013 年 8 月 10 日

---

搜索插件

**该插件尚未通过WordPress的最新3个主要版本进行测试**。 当与较新版本的WordPress一起
使用时，可能不再受到维护或支持，并且可能会存在兼容性问题。

![](https://s.w.org/plugins/geopattern-icon/super-cpt.svg)

# SuperCPT

 作者：[Matthew Boynes](https://profiles.wordpress.org/mboynes/)

[下载](https://downloads.wordpress.org/plugin/super-cpt.0.2.1.zip)

 * [详情](https://cn.wordpress.org/plugins/super-cpt/#description)
 * [评价](https://cn.wordpress.org/plugins/super-cpt/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/super-cpt/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/super-cpt/#developers)

 [支持](https://wordpress.org/support/plugin/super-cpt/)

## 描述

#### UPGRADE NOTICE

SuperCPT now uses Font Awesome instead of Glyphicons. Some icon names will carry
over, but not all. If this is a considerable inconvenience for you for a project,
simply do not update it. It’s not a security release, so updating isn’t necessary.

#### Overview

SuperCPT is an object wrapper for Custom Post Types, Custom Taxonomies, and Custom
Post Meta “for coders, by coders.” Simply put, SuperCPT:

 * DRYs up the Custom Post Type and Custom Taxonomy process (e.g. automatically 
   adds the name to all the labels),
 * allows you to set default options for all your Custom Post Types and Taxonomies,
 * significantly simplifies the process of creating, saving, and displaying Custom
   Post Meta,
 * is sexy! Your custom fields are styled to look great and SuperCPT comes with 
   361 awesome icons courtesy of [Font Awesome](http://fontawesome.io/).

#### Demo Video

#### TextMate/Sublime Text 2 Bundle

If you use TextMate, Sublime Text 2, or another editor which supports TextMate bundles,
check out [this set of snippets](https://github.com/mboynes/super-cpt-bundle) to
turbo-charge your development.

#### And more…

See the [Other Notes tab](https://wordpress.org/extend/plugins/super-cpt/other_notes/)
for instructions and demo code. Find more demos and a full reference [at GitHub](https://github.com/mboynes/super-cpt/wiki).

Since you’re a hard-core coder, [check this out on GitHub](https://github.com/mboynes/super-cpt)
if you want to contribute!

### Instructions

Depending on when and where you’re declaring your Custom Post Types and Taxonomies,
you have different options for which action to hook onto. `after_setup_theme` is
the safest bet, but if you’re referencing this in another plugin, `plugins_loaded`
is a good choice. To avoid a fatal error if something goes awry, you should check
to see if the class `Super_Custom_Post_Type` exists before referencing it. Don’t
worry about keeping up, reference code is below.

#### Custom Post Types

To define a new Custom Post Type, instantiate the `Super_Custom_Post_Type` class
with a string for the post type. For example,

    ```
    $movies = new Super_Custom_Post_Type( 'movie' );
    ```

It works very much like [`register_post_type`](https://codex.wordpress.org/Function_Reference/register_post_type).
The first thing you gained by using this is that the labels all got setup with either‘
Movie’ or ‘Movies’. If our post type were ‘indie-film’, the labels would have “Indie
Film” and “Indie Films” as appropriate. Of course, you do have the ability to set
the plural word in cases such as goose/geese. You also gained the ability to define
your own custom post type defaults through a filter. Lastly, you gained access to`
Super_Custom_Post_Type`‘s parent class, `Super_Custom_Post_Meta`, for fast, clean,
intuitive custom post meta, which we’ll go into shortly.

Lastly, if you’ve built a lot of custom post types, you’re probably sick and tired
of the pushpin icon. SuperCPT comes with 350 gorgeous icons courtesy of [Font Awesome](http://fontawesome.io/)
that are extremely easy to implement. Here’s what it looks like:

    ```
    $movies->set_icon( 'film' );
    ```

#### Custom Taxonomies

To define a new Custom Taxonomy, much like with Custom Post Types, you instantiate`
Super_Custom_Taxonomy` with a string for the term name. For example:

    ```
    $actors = new Super_Custom_Taxonomy( 'actor' );
    ```

Again, we got free labels for doing this, using either ‘Actor’ or ‘Actors’ as appropriate,
without needing to specify the 16 labels individually.

#### Custom Post Meta

Custom Post Meta is where SuperCPT shines the brightest, because this process is
typically the most time-consuming. `Super_Custom_Post_Meta` is a free-standing class
that can be added to any post type, even built-in post types (posts and pages). 
This class has a method `add_meta_box` which does the bulk of the work, and somewhat
mimics the WordPress function. Here’s an example:

    ```
    $movies->add_meta_box( array(
        'id' => 'features',
        'fields' => array(
            'tagline' => array( 'type' => 'text' )
        )
    ) );
    ```

The method `add_meta_box` takes an array of parameters (unlike the core function
which takes normal ordered arguments). `id` is the only required attribute, and 
that becomes the ID of the meta box as well as the title (this will get converted
into “words” for the title, e.g. `"movie_details"` would become “Movie Details”).`
fields` is an array of all the fields in the meta box. It’s an associative array,
where the keys in the array are the field names and the values are another associative
array of attributes for the field. The keys closely reflect the HTML attributes 
in the resulting field, and any key not known by the plugin will in fact become 
an HTML attribute (e.g. passing `'data-src' => 'foo'` would become the HTML attribute`
data-src="foo"` in the field). See the reference for the full gamut of options, 
both for the `add_meta_box` argument array and the fields array.

Long story short, using this class means you don’t have to do any additional work
to store data, retrieve data, style the boxes, and so on.

#### Helper Functions

SuperCPT has a couple of helper functions for displaying your post meta. `get_scpt_formatted_meta`
and `the_scpt_formatted_meta`

### Demo Code

Here is the full demo code:

    ```
    function scpt_demo() {
        if ( ! class_exists( 'Super_Custom_Post_Type' ) )
            return;

        $demo_posts = new Super_Custom_Post_Type( 'demo-post' );

        # Test Icon. Should be a square grid.
        $demo_posts->set_icon( 'th-large' );

        # Taxonomy test, should be like tags
        $tax_tags = new Super_Custom_Taxonomy( 'tax-tag' );

        # Taxonomy test, should be like categories
        $tax_cats = new Super_Custom_Taxonomy( 'tax-cat', 'Tax Cat', 'Tax Cats', 'category' );

        # Connect both of the above taxonomies with the post type
        connect_types_and_taxes( $demo_posts, array( $tax_tags, $tax_cats ) );

        # Add a meta box with every field type
        $demo_posts->add_meta_box( array(
            'id' => 'demo-fields',
            'context' => 'normal',
            'fields' => array(
                'textbox-demo' => array(),
                'textarea-demo' => array( 'type' => 'textarea' ),
                'wysiwyg-demo' => array( 'type' => 'wysiwyg' ),
                'boolean-demo' => array( 'type' => 'boolean' ),
                'checkboxes-demo' => array( 'type' => 'checkbox', 'options' => array( 'one', 'two', 'three' ) ),
                'radio-buttons-demo' => array( 'type' => 'radio', 'options' => array( 'one', 'two', 'three' ) ),
                'select-demo' => array( 'type' => 'select', 'options' => array( 1 => 'one', 2 => 'two', 3 => 'three' ) ),
                'multi-select-demo' => array( 'type' => 'select', 'options' => array( 'one', 'two', 'three' ), 'multiple' => 'multiple' ),
                'date-demo' => array( 'type' => 'date' ),
                'label-override-demo' => array( 'label' => 'Label Demo' )
            )
        ) );

        # Add another CPT to test one-to-one (it could just as easily be one-to-many or many-to-many)
        $linked_posts = new Super_Custom_Post_Type( 'linked-post', 'Other Post', 'Other Posts' );
        $linked_posts->add_meta_box( array(
            'id' => 'one-to-one',
            'title' => 'Testing One-to-One relationship',
            'context' => 'side',
            'fields' => array(
                'demo-posts' => array( 'type' => 'select', 'data' => 'demo-post' ),
                'side-wysiwyg' => array( 'type' => 'wysiwyg' )
            )
        ) );
        $linked_posts->set_icon( 'cogs' );

    }
    add_action( 'after_setup_theme', 'scpt_demo' );<h3>To-Do</h3>
    ```

1. Add better support for multiple fields for one meta key
 2. Add easy RSS feeds,
e.g. in fields array, a parameter might be `'rss' => 'PubDate'` to prefer that field’s
data over the post’s publication date.

## 安装

Upload the SuperCPT plugin to your blog/site and activate it. You know, like every
other plugin.

## 常见问题

  What icons are available?

You’ll find a full list in Tools > SuperCPT

  I don’t want my clients seeing the icon list, is there a way to hide it?

Yes. In your plugin or theme, add: `add_filter( 'scpt_show_admin_menu', '__return_false');`

  I’m not a programmer, can I/how do I use this plugin?

You probably shouldn’t. Check out [Custom Post Type UI](https://wordpress.org/extend/plugins/custom-post-type-ui/),
[More Fields](https://wordpress.org/extend/plugins/more-fields/), and [Types – Custom Fields and Custom Post Types Management](https://wordpress.org/extend/plugins/types/).

## 评价

此插件暂无评价。

## 贡献者及开发者

「SuperCPT」是开源软件。 以下人员对此插件做出了贡献。

贡献者

 *   [ Matthew Boynes ](https://profiles.wordpress.org/mboynes/)
 *   [ Union Street Media ](https://profiles.wordpress.org/unionstreetmedia/)

[帮助将「SuperCPT」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/super-cpt)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/super-cpt/)，查看[SVN仓库](https://plugins.svn.wordpress.org/super-cpt/)，
或通过[RSS](https://plugins.trac.wordpress.org/log/super-cpt/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/super-cpt/)。

## 更新日志

#### 0.2.1

 * Improving PHP <5.3 support

#### 0.2

 * Some bug fixes
 * Removed glyphicons in favor of the open-source GPL-compatible Font Awesome
 * Fixed bug where CSS/JS doesn’t load if plugin is in mu-plugins (props to Aaron
   Holbrook)
 * Added magic methods for accessing and setting taxonomy and post type attributes
   after declaration
 * Added “media” field type
 * Added ability to have default values (props to github.com/Gyroscopic for the 
   suggestion)
 * Added ability to add taxonomies to the manage posts columns (props to github.
   com/Gyroscopic for the suggestion)
 * Added ability to include the featured image in the manage posts columns (props
   to twitter.com/GreggFranklin for the suggestion)

#### 0.1

Beta Release. Everything is new!

## 额外信息

 *  版本 **0.2.1**
 *  最后更新：**13 年前**
 *  活跃安装数量 **600+**
 *  WordPress 版本 ** 3.0 或更高版本 **
 *  已测试的最高版本为 **3.6.1**
 *  语言
 * [English (US)](https://wordpress.org/plugins/super-cpt/)
 * 标签
 * [cms](https://cn.wordpress.org/plugins/tags/cms/)[custom field](https://cn.wordpress.org/plugins/tags/custom-field/)
   [custom fields](https://cn.wordpress.org/plugins/tags/custom-fields/)[custom post type](https://cn.wordpress.org/plugins/tags/custom-post-type/)
   [custom post types](https://cn.wordpress.org/plugins/tags/custom-post-types/)
 *  [高级视图](https://cn.wordpress.org/plugins/super-cpt/advanced/)

## 评级

 5 星（最高 5 星）。

 *  [  14 条 5 星评价     ](https://wordpress.org/support/plugin/super-cpt/reviews/?filter=5)
 *  [  0 条 4 星评价     ](https://wordpress.org/support/plugin/super-cpt/reviews/?filter=4)
 *  [  0 条 3 星评价     ](https://wordpress.org/support/plugin/super-cpt/reviews/?filter=3)
 *  [  0 条 2 星评价     ](https://wordpress.org/support/plugin/super-cpt/reviews/?filter=2)
 *  [  0 条 1 星评价     ](https://wordpress.org/support/plugin/super-cpt/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/super-cpt/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/super-cpt/reviews/)

## 贡献者

 *   [ Matthew Boynes ](https://profiles.wordpress.org/mboynes/)
 *   [ Union Street Media ](https://profiles.wordpress.org/unionstreetmedia/)

## 支持

有话要说吗？是否需要帮助？

 [查看支持论坛](https://wordpress.org/support/plugin/super-cpt/)

## 捐助

您愿意支持这个插件的发展吗?

 [ 捐助此插件 ](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=22PRU6U4U78RC)