如何显示更多帖子

时间:2015-05-12 06:45:47

标签: javascript json wordpress api

我收到一个JSON对象,其中包含来自WordPress帐户的一些帖子,但我只收到大约15个帖子,我该怎么办才能获得超过这个数量?

JSON看起来像这样

GET http://localhost:8080/build/production/recommendation/.js?_dc=1431411762018 404 (Not Found)
  Ext.Boot.Ext.Boot.d.fetch 
  Ext.Boot.Ext.Boot.r.fetch 
  Ext.Boot.Ext.Boot.r.loadSync  
  Ext.Boot.Ext.Boot.r.load  
  Ext.Boot.Ext.Boot.k.loadEntries   
  Ext.Boot.Ext.Boot.d.processRequest    
  Ext.Boot.Ext.Boot.d.loadSync  
  Ext.Boot.Ext.Boot.d.load  
  Ext.apply.loadScripts 
  Ext.apply.load    
  Ext.apply.require 
  Ext.apply.syncRequire 
  Ext.Function.o.alias  
  Ext.ClassManager.Ext.apply.create 
  Ext.ClassManager.Ext.apply.instantiateByAlias 
  Ext.apply.factory 
  Ext.cmd.derive.applyAxes  
  k 
  Ext.Configurator.configure    
  Ext.Base.r.addMembers.initConfig  
  Ext.cmd.derive.constructor    
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  (anonymous function)  
  Ext.ClassManager.Ext.apply.create 
  Ext.cmd.derive.loginSuccess   
  Ext.widget.submit.success 
  Ext.apply.callback    
  Ext.cmd.derive.afterAction    
  Ext.cmd.derive.onSuccess  
  Ext.apply.callback    
  Ext.cmd.derive.onComplete 
  Ext.cmd.derive.onStateChange  
  Ext.Function.o.bind   
Uncaught TypeError: object is not a function
  (anonymous function)  
  Ext.ClassManager.Ext.apply.create 
  Ext.ClassManager.Ext.apply.instantiateByAlias 
  Ext.apply.factory 
  Ext.cmd.derive.applyAxes  
  k 
  Ext.Configurator.configure    
  Ext.Base.r.addMembers.initConfig  
  Ext.cmd.derive.constructor    
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  Ext.ClassManager.Ext.apply.widget 
  Ext.cmd.derive.create 
  Ext.cmd.derive.lookupComponent    
  Ext.cmd.derive.privates.prepareItems  
  Ext.cmd.derive.add    
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initItems  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.initComponent  
  Ext.cmd.derive.constructor    
  ai    
  (anonymous function)  
  Ext.ClassManager.Ext.apply.create 
  Ext.cmd.derive.loginSuccess   
  Ext.widget.submit.success 
  Ext.apply.callback    
  Ext.cmd.derive.afterAction    
  Ext.cmd.derive.onSuccess  
  Ext.apply.callback    
  Ext.cmd.derive.onComplete 
  Ext.cmd.derive.onStateChange  
  Ext.Function.o.bind   

我正在向{ ID: 4164, title: "24 Horas Non-Stop con Marco Carola", status: "publish", type: "post", author: { ID: 11, username: "VIlma Quiros", name: "VIlma Quiros", first_name: "VIlma", last_name: "Quiros", nickname: "VIlma Quiros", slug: "vilma-quiros", URL: "", avatar: "", description: "", registered: "2015-04-16T07:04:04+00:00", meta: { links: { self: "http://urbanetradio.com/wp-json/users/11", archives: "http://urbanetradio.com/wp-json/users/11/posts" } } }, content: "<p class="p2"><a href="http://urbanetradio.com/wp-content/uploads/2015/05/PRUEBA-1.png"</p> <p><iframe src="https://www.youtube.com/embed/AV6nAmjDynE" width="750" height="422" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p> ", parent: null, link: "http://urbanetradio.com/24-horas-non-stop-con-marco-carola/", date: "2015-05-08T18:42:33", modified: "2015-05-08T20:20:10", format: "standard", slug: "24-horas-non-stop-con-marco-carola", guid: "http://urbanetradio.com/?p=4164", excerpt: "<p>El pasado fin de semana, Marco Carola dio un show maratónico en el Festival Sunwaves 2015 al mezclar por no menos de 24 horas seguidas. &#8230;</p> ", menu_order: 0, comment_status: "closed", ping_status: "open", sticky: false, date_tz: "America/Costa_Rica", date_gmt: "2015-05-09T00:42:33", modified_tz: "America/Costa_Rica", modified_gmt: "2015-05-09T02:20:10", ...

发送获取请求

此处为API http://wp-api.org/

的文档

我无法在JSON中看到比上面更大的内容,任何提及帖子增加的属性/属性。

2 个答案:

答案 0 :(得分:1)

您可以使用?filter[posts_per_page]=30

显示更多帖子

修改 它似乎对你不起作用(甚至文档中提供的示例都不适用)

http://urbanetradio.com/wp-json/posts?filter[posts_per_page]=8&filter[order]=ASC

所以我假设你的配置有问题。

如果你尝试重新配置后这对你不起作用,我会建议一个替代方案:JSON API plugin,它对我很有用,也很可能也适合你。

答案 1 :(得分:0)

我相信您正在向/ sites / $ site / posts / endpoint发送GET请求以获取JSON。您可以发送一个查询参数,询问您想要的帖子数量以及网址

?number=20

可以检索的最大帖子数限制为100个。

https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/posts/