The other week I created a pretty cool web part that displays the top X blog postings that have been viewed on a particular SharePoint blog site. It turned out that a lot more was involved to get this functionality to work, but in the end I ended up with a decent reusable web part.
Here are the basic steps to achieve the functionality:
- Create a feature
- Created a feature receiver which on activate, would look for the Posts list in the blog site and add a “PageViews” column to it which will store the number of times the blog posting has been viewed
- A custom web part which will read the Posts list and display the top X blog postings based on “PageViews”
- A custom control which record posting “views” and has to be added to the master page…this piece is really the core of the solution. Basically what it does is since its on the master page, every page within the site will run this control. The control has logic to basically only jump into action if the page your viewing is a blog posting. If the page your viewing is a blog posting, it will then increment the “PageViews” column for the specific posting in the Posts list.
The real struggle was the logic to only record clicks if the page your viewing is a blog posting page and not some other page on the site. In addition, I need to include some logic to exclude the search crawler, since these views really aren’t legit.
I will post the code up shortly once I clean it up a bit, it will take me a few days to clean up some of the kinks.
e522b8be-8dab-4bf8-9357-ea0c9ed7cd0e|0|.0