hanamura/wp-post-type
Composer 安装命令:
composer require hanamura/wp-post-type
包简介
Custom Post Type utility for WordPress.
README 文档
README
Custom Post Type utility for WordPress.
Example
<?php // extend PostType class and create your own post type class MyPostType extends \WPPostType\PostType { function __construct() { // set post type name: 'my-post-type' // - archive page: yoursite.com/my-post-type // - single page: yoursite.com/my-post-type/post-slug parent::__construct('my-post-type', array( // second argument of `register_post_type()` // see: http://codex.wordpress.org/Function_Reference/register_post_type 'supports' => array('title', 'editor'), 'has_archive' => true )); } // compose edit screen public function onAddMetaBoxes() { // create 'Info' box add_meta_box( 'my-post-type-info', 'Info', array($this, 'addMetaInfo'), $this->name ); } public function addMetaInfo($post) { // input tags for custom fields: 'nickname' and 'birth_year' ?> <p> Nickname<br> <input type="text" name="nickname" value="<?php echo esc_attr($post->nickname) ?>"></input><br> </p> <p> Birth Year<br> <input type="number" name="birth_year" value="<?php echo esc_attr($post->birth_year) ?>"></input> </p> <?php } public function onCheckedSavePost($post_id, $post) { $params = stripslashes_deep($_POST); // save custom values in a custom way if (isset($params['nickname'])) { $value = trim($params['nickname']); update_post_meta($post_id, 'nickname', $value); } if (isset($params['birth_year'])) { $value = intval($params['birth_year']); update_post_meta($post_id, 'birth_year', $value); } } } // register 'my-post-type' new MyPostType();
统计信息
- 总下载量: 1.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-02-13