2012-02-16 66 views
0

我试图导入Wordpress RSS源中的最后5篇文章并在我的网站上显示它们。我需要一些帮助从Wordpress导入RSS订阅

我正在使用它,但它抓住了整个饲料。

<asp:DataList ID="dataNews" runat="server" DataSourceID="xmlSource" > 
     <ItemTemplate> 
      <a href="<%# XPath("link") %>"><%# XPath("title") %></a> 
     </ItemTemplate> 
</asp:DataList> 
<asp:XmlDataSource ID="xmlSource" runat="server" DataFile="http://myblog.com/feed" XPath="rss/channel/item" EnableCaching="true" /> 

我该如何做到这一点?

回答

2

您可以使用XPath表达式来帮助您完成此操作,如此处所述:Get a specific number of results from an XmlDocument XPath query。以下应该工作。

<asp:XmlDataSource ID="xmlSource" runat="server" DataFile="http://myblog.com/feed" XPath="rss/channel/item[position()<6]" EnableCaching="true" /> 
+0

This works。非常感谢!但是,如果我的博客Feed已关闭,它会错误显示我的整个首页。我是否应该在后面的代码中写出所有内容,或者是否有一些与我的代码相关的选项? – 2012-02-17 14:38:55