monkeyscode/listing

创建一个渲染数据列表的短代码

此包的官方仓库似乎已消失,因此该包已被冻结。

1.2.6 2017-11-29 01:39 UTC

This package is not auto-updated.

Last update: 2019-06-29 02:25:59 UTC


README

在WordPress中使用WP_Query创建短代码

安装

composer require monkeyscode/listing

用法

初始化

通过创建类Listing的实例来初始化列表。

use MSC\Listing;

$list = new Listing();

使用模块作为默认:[listing]

自定义列表

use MSC\Listing;

class MyListing extends Listing
{
    public function __construct()
    {
        parent::__construct();
    }

    public function handle($query, $opts)
    {
        // handle data and display it on front-end
    }
}

new MyListing;

如何为列表传递我们自己的选项

$customListing = new Listing;

$myCustomAttr = [
	'option_1' => '',
	'option_2' => ''
];
$customListing->setCustomAttrs($myCustomAttr);

现在我们可以使用以下选项: [listing option_1="value_1" option_2="value_2"]

选项

选项 默认值 描述 模式
post_type post 指定帖子类型 _
per_page 6 每页帖子数 _
user null 帖子的用户 _
cat null 分类列表 _
tag null 标签列表 _
taxonomy null 分类和其术语列表 tax1(term_id1:term_id2...),tax2(term2_id1,term2_id2...)
status publish 匹配条件的帖子的状态 publish,draft,pending...
excludes '' 您想排除的帖子的ID字符串 例如:"1,2,3,4.."
orderby '' 排序字段 _
paged no 启用分页或不启用分页 _
filter no 启用/禁用过滤功能 _
layout '' 向列表传递模板 _

贡献者

Duy Nguyen