0

I'm trying to import the last 5 posts from a Wordpress RSS feed and show them on my site.

I was using this, but it grabs the whole feed.

<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" />

How can I accomplish this?

Trey Copeland
  • 3,387
  • 7
  • 29
  • 46

1 Answers1

2

You can use XPath expressions to help you with this as documented here: Get a specific number of results from an XmlDocument XPath query. The following should work.

<asp:XmlDataSource ID="xmlSource" runat="server" DataFile="http://myblog.com/feed" XPath="rss/channel/item[position()<6]" EnableCaching="true" />
Community
  • 1
  • 1
Dharun
  • 613
  • 8
  • 26
  • This works. So thanks for that! But if I blog feed is down, it will error out my whole front page. Should I write this all in the code behind or is there some options to do with my code? – Trey Copeland Feb 17 '12 at 14:38