swancreative / laravel-wp-api
基于 threesquared 分支的 Laravel WordPress JSON REST API 包
3.1
2022-02-02 12:06 UTC
Requires
- php: ^7.0|^8.0
- guzzlehttp/guzzle: 7.4.1
Requires (Dev)
- phpunit/phpunit: 9.5.*
README
Laravel 5 包,用于 WordPress JSON REST API
安装
只需将以下行添加到您的 composer.json 文件中,并运行安装/更新命令
"mattwilding/laravel-wp-api": "~2.0"
配置
您需要在 config/app.php 文件中添加服务提供者和可选的外观别名
'providers' => array( Mattwilding\LaravelWpApi\LaravelWpApiServiceProvider::class ) 'aliases' => array( 'WpApi' => Mattwilding\LaravelWpApi\Facades\WpApi::class ),
并将包配置文件发布以配置您的 WordPress 安装位置
php artisan vendor:publish
用法
该包提供了一种简化的接口,用于调用一些现有 API 方法,这些方法在 此处 文档中进行了说明。您可以使用提供的外观或注入 Mattwilding\LaravelWpApi\WpApi 类。
文章
WpApi::posts($page);
页面
WpApi::pages($page);
文章
WpApi::post($slug);
WpApi::postId($id);
分类
WpApi::categories();
标签
WpApi::tags();
分类文章
WpApi::categoryPosts($slug, $page);
作者文章
WpApi::authorPosts($slug, $page);
标签文章
WpApi::tagPosts($slug, $page);
搜索
WpApi::search($query, $page);
存档
WpApi::archive($year, $month, $page);