add helper plugins list_posts,get_posts#467
Merged
Merged
Conversation
compatible, optimizing
Contributor
Author
There was a problem hiding this comment.
考虚到options.count参数有可能人为置空的情况.像{count:''}
Contributor
Author
|
OK,改好了.統一風格的代碼看起來會比較舒服. |
tommy351
added a commit
that referenced
this pull request
Feb 5, 2014
add helper plugins `list_posts`,`get_posts`
|
Guys, is there are way to skip certain number of articles in the query? I need articles 5 to 8 for example. |
Contributor
Author
|
var posts = get_posts({query:{tags: 'GRUB4DOS'}}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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可使用的值为orandnotnor;你还可以添加其它查询,比如,以下查找id是8的文章(当然了你需要在文章中设置id的值.)
查询参数还可以是一个自定义函数,function(data){return xxxxxx}
这个函数可以自己写,只有一个参数,
以下例子就可以列出包含字符串"通用"的文章
通过自定义函数,你可以实现功能更强大的查询;
简单应用例子
获取最近更新的8个贴子列表
获取最近更新的并且有带标签'GRUB4DOS'的贴子
在主题中使用,可以根据文章的标签和分类查找相关贴子 Related posts #437
operator是or,所以只要分类或标签有在列表中就行.获取随机贴子列表
注: 参数可以组合使用,这样很方便提取特定的文章..
以上是list_posts的功能,主要是返回一个网页可显示的列表.
如果你还需要自己处理,这时可以使用
get_posts如下,可以获取到包含标签
grub4dos的所有文章.