wp-xu/xu
最新稳定版本:v1.2.0
Composer 安装命令:
composer require wp-xu/xu
包简介
Collection of useful WordPress and PHP functions and classes
README 文档
README
Requires PHP 5.5.9 and WordPress 4.4
Collection of useful WordPress and PHP functions and classes.
Install
$ composer require frozzare/wp-xu
Documentation
Some cached functions requires that wp_cache_delete_group function exists to delete cache group.
Models
With xu you can create models that you load from your theme (with xu_get_model) or any where, just use the class.
<?php use Xu\Model\Model; class Post extends Model { /** * Get model attributes. * * @return array */ public function get_attributes() { return [ 'title' => $this->post->post_title ]; } }
In your template file:
$model = xu_get_model( 'post' ); echo $post->title;
The model class implements a lot of methods like to_array and to_json to convert the model to a array or JSON string.
Models Collection
A collection is a collection of one or more models. By reading the api reference docs you can find out which methods a collection has, first, last, filter, map, reject and where is some of the methods that exists.
A collection can be created in different ways:
use Xu\Model\Collection; $collection = new Collection( [$model1, $model2] ); $collcetion = Post::collection( [$model1, $model2] ); class List extends Model { /** * Get all posts that exists on `post` post type. * * @return \Xu\Model\Collection */ public function posts() { return static::collection( get_posts( 'post_type=post' ) ); } } $collection = ( new List )->posts();
License
MIT © Fredrik Forsmo
统计信息
- 总下载量: 3.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-30