hanamura/wp-post-type 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固