I am in the process of re-working my personal website with a Win8 theme and wanted to retain my existing WordPress blog as is (for SEO and because WordPress is a great blogging platform) but wanted to also have the blog content on the new site.

Getting the feed from WordPress of the most recent items is dead easy as it is exposed as an RSS feed so all that’s required is to parse the feed and re-render the content on the new blog page which you can see here http://bondigeek.com/TheBlog.

I have added some of the additional stuff to the code above for clarity but the first block does all the work of parsing using XDocument and LINQ

Code below the break

The Controller – Parsing code with some added fluff specific to my site

private BlogModel LoadBlogModel() { //Create the new BlogModel and List of BlogItemModel BlogModel BlogModel = new BlogModel(); List items = new List(); // * THESE 2 LINES HERE ARE THE KEY ONES FOR READING THE POSTS * // Load the rss feed from the blog XDocument feed = XDocument.Load("http://bondigeek.com/blog/feed/"); // Filter out just the post items var posts = (from item in feed.Root.Element("channel").Descendants("item") select item).ToList(); // This is just a filler for the first tile to describe the page BlogItemModel newItem = new BlogItemModel(); newItem.Title = "BondiGeek Blog"; newItem.BlogBrief = "Here you will find some of the most recent
blog posts from my WordPress blog.
Hope you enjoy one or two."
; newItem.PostUrl = "http://bondigeek.com/blog/"; newItem.PublishedOn = DateTime.MinValue; newItem.TileColor = "green blog"; items.Add(newItem); int index = 1; // Iterate over each blog post and pull out the various elementsforeach (XElement item in posts) { newItem = new BlogItemModel(); newItem.Title = item.Element("title").Value; newItem.BlogBrief = item.Element("description").Value; newItem.PostUrl = item.Element("link").Value; newItem.PublishedOn = DateTime.Parse(item.Element("pubDate").Value); //This is here to alternate the color class applied to each tileswitch (index) { case 1: newItem.TileColor = "orange"; index++; break; case 2: newItem.TileColor = "red"; index++; break; case 3: newItem.TileColor = "lightgreen"; index++; break; case 4: newItem.TileColor = "blue"; index++; break; case 5: newItem.TileColor = "lightblue"; index++; break; case 6: newItem.TileColor = "purple"; index++; break; case 7: newItem.TileColor = "green"; index = 1; break; } items.Add(newItem); } // Add the items to the model BlogModel.BlogItems = items; // Return the model for the blog pagereturn BlogModel; } }

**The Model** publicclass BlogItemModel { publicstring Title { get; set; } public DateTime PublishedOn { get; set; } publicstring BlogBrief { get; set; } publicstring PostUrl { get; set; } publicstring TileColor { get; set; } }

The View

@model BondiGeek.Models.BlogModel @{ ViewBag.Title = "Blog"; } @foreach (var item in Model.BlogItems) {

class="panel wide @item.TileColor"> class="blog-title">@Html.DisplayFor(modelItem => item.Title) class="blog-brief">@Html.Raw(item.BlogBrief) @if (item.PublishedOn != DateTime.MinValue) { "@Html.DisplayFor(modelItem => item.PostUrl)" target="blank">class="text-bottom-left">Read more >> class="text-bottom-right">@Html.DisplayFor(modelItem => item.PublishedOn) } else { "@Html.DisplayFor(modelItem => item.PostUrl)" target="blank">class="text-bottom-left">Visit the Blog >> }
}

Too easy!

BondiGeek