Trey Copeland
Trey Copeland

Reputation: 3527

I need some help importing an RSS feed from Wordpress

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?

Upvotes: 0

Views: 310

Answers (1)

Dharun
Dharun

Reputation: 613

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

Upvotes: 2

Related Questions