Top Posts Extension for BlogEngine.net

I decided to put together a BlogEngine extension that will display the top posts based on the number of comments they've received.  I've been wanting this extension for a long while, and I decided to bite the bullet and put it together myself.

Why isn't there a Top Post class for BlogEngine?

I've looked around quite a bit for this component and to my surprise, I never found one.  The closest I've come to something similar is Cristiano Fino's Top Commenters component for BlogEngine.  After the amazement of not finding an existing component wore off, I decided to put one together.

Mind you, I'm still getting comfortable working within BlogEngine, and each time I do I learn a little more about the engine itself.  If this extension could benefit from any code changes, please let me know.

My main point of concern is the way I refer to the Posts collection.  You'll see in the following code snippet that I define a new List collection of Post objects.  I then needed to sort the collection to obtain the top commented posts that define the top posts to obtain.  So, to not effect the ordering for anything that may use the collection later, I make a copy of the collection and sort that instead.

// Make a copy of the posts collection so that it doesn't impact normal rendering
// after we sort it
List<Post> posts = new List<Post>();
posts.AddRange(Post.Posts);

// Sort the items based on number of comments
posts.Sort(delegate(Post post1, Post post2)
{
    return Comparer<int>.Default.Compare(post2.Comments.Count, post1.Comments.Count);
});

If this method can be improved or done in a way that is more efficient, please let me know.

Why the Top Posts Extension?

I wanted this extension for a few reasons.  The foremost being that I wanted to highlight some of the more popular posts found on my blog (if you can define comment count as popular).  I wanted new readers to be able to see some of the more active posts within the archives.  I decided display the top 5 commented posts.

Another reason was to punch through an extension for BlogEngine.  I've been sitting on doing one for a long while now, and I finally found the time and drive to bust this out. 

Finally, I also wonder if this will be included in the core.  I find it remarkable that it isn't there already.  Perhaps this will inspire the devs to include it?

Implementing the Top Posts Extension

Implementing the extension is easy.  Simply copy the TopPost.cs file to your App_Code/Extensions folder.  Once there, you can then place the following in your site.master theme file:

<blog:TopPosts MaxNumber="5" ID="TopPosts1" runat="server" />

MaxNumber - The number of posts to display

Download the Top Posts Extension

I know this will work for BE 1.3 or greater...

Single file in a zip - Download TopPosts.zip (2kb)

I've also put a Download page in place to capture any future extensions or themes I might put together.

Feature Requests

Modifying the control may be easy for some, and not so for others.  If there are any changes you think would be good to include, leave a comment and let me know.  I'd be happy to work them in for you.

permalink Permalink or Trackback Comment Comments (4) Cat Web Development
Technorati: No reaction yet!
Tags: , ,
Actions: E-mail

Was this helpful?

If you liked this or found it helpful, please digg it, stumble it, buzz it, whatever it, to say thank you.





Add to Technorati Favorites

 
 If you would like to receive these posts as they happen, you can subscribe to my feed or receive my posts in your email.

Related Posts

Comments

  1. Muhammad Mosa
    Muhammad Mosa Says:


    That is cool Wayne my friend. But Also you can implement it as widget instead of adding the control to master page! what do you think?
  1. Wayne
    Wayne Says:


    @Muhammad - Yeah, that would be the next step for it. Although, I don't make use of the widget functionality found in BE yet. In fact, I removed it. I wanted to work with each control individually and not have to have them all in a "single line" as well.

    When BE went widgets, I was only 4 months in to learning BE, so I have much to learn before I dig into that. Like I said though, that would be the next logical step for this.

    If you have the bandwidth for that, feel free to take it and mod it into a widget. I for one, am stretched a bit thin. Smile

  1. Demeur
    Demeur Says:


    I like to see who's been blabbing but I think I'd have to change the margins on my blog and I've just been too lazy of late. Also I see that names are case sensitive. There's two of me in the top comments. D and d
  1. Wayne
    Wayne Says:


    @Demeur - Yeah, I either need to control that up front when you enter your name, or on the back-end when I display the list. I've been eyeballing that for some time and considering which way would be best to handle it.

    I've noticed that a lot recently. I'll watch things and simply consider them for a bit, and then BAM, correct it one day.

Add comment



(Will show your Gravatar icon)  

biuquote
  • Comment
  • Preview
Loading



Check it out mango: Any links must be entered as http://www.somewhere.com with nothing touching it. Anything else will be mangled. This is to help combat spam and to also ensure the masses know of this little tidbit before they click Save comment below. :) I have this down to remind me to do something with it, but I take things slow and easy on the old horse.

Keeps her regular don't ya know, and I wouldn't want to disturb that.



CSS Template by RamblingSoul | Illinois Wine. Adapted to BlogEngine by Wayne John
EatonWeb Blog Directory  Blog Directory Blogger Forum: About Blogging for Bloggers DaniWeb - IT Professionals' Lounge Community