joomla visitors
Mithila Software Blog | BlogEngine.Net Extension to show related posts inside post content

BlogEngine.Net Extension to show related posts inside post content

January 01, 2013 Posted by Mithila Software

You can show related posts inside post content of your blog based blog with the help of the extension below.Simply place this code (c#) in your BlogEngine.Web\App_Code\Extensions folder of blog directory.The related will show at top-left of the blog but you can customize it by tweaking the codes below.


using BlogEngine.Core.Web.Extensions;
namespace App_Code.Extensions
 using System;
 using System.Web;
 using BlogEngine.Core;
 using BlogEngine.Core.Web.Controls;
 using System.IO;
 using System.Text;
 using System.Collections.Generic;
 using System.Globalization;
 /// <summary>
 /// Summary description for CustomEmbed
 [Extension("Shows related posts inside the current post ", "1.0", "")]
 public class RelatedPostsinPost
 static List<string> postimages = new List<string>();
 static RelatedPostsinPost()
 Post.Serving += new EventHandler<ServingEventArgs>(Serving);
 private static void Serving(object sender, ServingEventArgs e)
 if (e.Location == ServingLocation.SinglePage || e.Location == ServingLocation.SinglePost)
 Post post = (Post)sender;
 string body = post.Content;
 var relatedPosts = Search.FindRelatedItems((IPublishable)post);
 var relatedPosts2 = relatedPosts.GetRange(0, Math.Min(5, relatedPosts.Count));
 string rpc = "<div style=\"background-color: #F2F2F2;margin: 0;overflow: hidden;float:left;margin-right:10px;\"><div style=\"height:40px;background-color:#C4CDE0;vertical-align:top;display:inline-block;width:100%;line-height: 40px;text-align:center;color:#000000;\">Related News</div><ul style=\"color: #5B7CA5;display: block;font-size: 14px;list-style-position: inside;list-style-type: square;text-decoration: none;\">";
 foreach (var item in relatedPosts2)
 rpc += "<li style=\"border-bottom: 1px solid #CBCBCB;font-family: Georgia,Times New Roman,Times,serif;padding: 5px 0px;width: 284px;\">" + string.Format("<a style=\"color: #0A67A4;text-decoration: none;\" href={0}>{1}</a>", item.RelativeLink, item.Title) + "</li>";
 e.Body = rpc + "</ul> <img style=\"float:right;\" src=\http://<location to empty image>/336x280t.jpg\ /></div>" + e.Body;
blog comments powered by Disqus
Address ::
Mithila Software Solutions,
Green House , 3 GM Road ,
Near Radio Station , Darbhanga
PIN:: 846004
Phone :: # 099-397-49350