This project is read-only.

List five latest posts

Sep 6, 2012 at 5:10 PM


I'm sure this is common but searching here/google hasn't turned up much.

I would like to list the five latest blog posts on my homepage, and link to them. I believe I need something like

BlogEngine.Core.Post.Posts.Where(p => p.IsPublished)

I've tried putting it in a foreach loop and doing something with it but no luck so far.

Can someone point me in the right direction please?

Thank you 


Sep 7, 2012 at 12:36 PM

I did some more searching and figured it out:


List<BlogEngine.Core.Post> posts = new List<Post>(BlogEngine.Core.Post.Posts);                       
for (int i = 0; i < Math.Min(5, posts.Count); i++)                        {                        
string title = posts[i].Title;                        
string link = posts[i].RelativeLink;                           
Response.Write("<a href=\"link\">" + title + "</a><br />");