开发者

How to get the number of pages/posts from a Wordpress RSS feed with a Java servlet

I am co开发者_运维百科ding a servlet, where I want to read in Wordpress feed. How do i get number of posts/pages from the wordpress feed? Is there any URL parameter?

And assuming that each page has fixed # of posts (6 in my case)


Wordpress feeds use RSS, so you need to use a Java RSS library.

Question (and answer) here: java library for reading RSS and ATOM feeds

Answer, quoted:

Have you had a look into the following list? http://java-source.net/open-source/rss-rdf-tools

Even though it has been mentioned several times, I would suggest using Rome as well.

Update: Wordpress also has an XmlRpc API, so you can use that to query posts. The closest to I can see to getting the number of posts/pages is to use wp.getPageList which returns an array of all posts with minimal data.

As part of the XmlRpc API support, Wordpress implements several standards including the Blogger API, for which there is a decent tutorial. Again, no specific 'getPostCount()' function.

public static void printAllPosts(
    GoogleService myService, String blogId)
    throws ServiceException, IOException {
  // Request the feed
  URL feedUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/posts/default");
  Feed resultFeed = myService.getFeed(feedUrl, Feed.class);

  // Print the results
  System.out.println(resultFeed.getTitle().getPlainText());
  for (int i = 0; i < resultFeed.getEntries().size(); i++) {
    Entry entry = resultFeed.getEntries().get(i);
    System.out.println("\t" + entry.getTitle().getPlainText());
  }
  System.out.println();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜