add helper plugins list_posts
,get_posts
#467
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
使用这两个可以很方便的获取符合条件的文章.
默认参数如下:
query参数介绍
加上
query
参数可以根据指定条件查询符合条件的文章.若设置了
tags
参数,只要文章的标签有其中之一该文章就会被列出来.categories
参数和tags
参数一样.根据分类查询.tags
和categories
可以使用字符串(多个使用','分隔)或数组,还可以直接从post中获取,比如post.tags注: 为了使用方便,有经过特殊处理,标签和分类查找是不区分大小写的.所以
grub4dos
和GRUB4DOS
是一样的operator
是操作符号,指定查询条件的关系,默认是'and',每一个查询条件都要符合.如果是'or',就是只要有一个条件符合就行了.operator
可使用的值为or
and
not
nor
;你还可以添加其它查询,比如,以下查找id是8的文章(当然了你需要在文章中设置id的值.)
查询参数还可以是一个自定义函数,function(data){return xxxxxx}
这个函数可以自己写,只有一个参数,
以下例子就可以列出包含字符串"通用"的文章
通过自定义函数,你可以实现功能更强大的查询;
简单应用例子
获取最近更新的8个贴子列表
获取最近更新的并且有带标签'GRUB4DOS'的贴子
在主题中使用,可以根据文章的标签和分类查找相关贴子 Related posts #437
operator
是or
,所以只要分类或标签有在列表中就行.获取随机贴子列表
注: 参数可以组合使用,这样很方便提取特定的文章..
以上是list_posts的功能,主要是返回一个网页可显示的列表.
如果你还需要自己处理,这时可以使用
get_posts
如下,可以获取到包含标签
grub4dos
的所有文章.