Using the current widgets on other sites.

Jan 20, 2011 at 3:43 AM

Hi all,

Sorry, very new and this is probably very simple but I have been wondering around in the dark for a while now so I have to ask.

I want to include and iFrame on the home page of a site that just displays recent posts, then when clicked takes you to the blog and the clicked post.

Setup is, I have a home page in the root directory and a folder named Blog with the blog in it.

Can someone please point me in the right direction?

Cheers,

Mike

Coordinator
Jan 20, 2011 at 9:15 AM

Where your blog is, in the root folder, create a new file named "recent_posts.aspx" (any name actually works).  Put the code below into it.  You can then point your iframe to the URL of this new page.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="BlogEngine.Core" %>

<script runat="server">

	protected override void OnLoad(EventArgs e)
	{
		base.OnLoad(e);

		const string Link = "<li><a target=\"_top\" href=\"{0}\">{1}</a></li>";
		var sb = new StringBuilder();
		sb.Append("<ul class=\"recentPosts\" id=\"recentPosts\">");
		int count = 0;

		foreach (Post post in Post.Posts)
		{
			if (post.IsVisibleToPublic)
			{
				count++;
				sb.AppendFormat(Link, post.AbsoluteLink, HttpUtility.HtmlEncode(post.Title));
				if (count > 5) { break; }
			}
		}

		sb.Append("</ul>");
		litRecentPosts.Text = sb.ToString();
	}

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Recent Posts</title>
</head>
<body>
	<asp:Literal ID="litRecentPosts" runat="server" EnableViewState="false" />
</body>
</html>
Jan 21, 2011 at 11:56 PM

Thanks BenAmada,

Got that working fine, I can see that it is similar to the code in the /controls/RecentPosts.cs file. Can’t I derive from that code in the .aspx file in the root directory somehow? I'm trying to get it to display the “Comment Count” and “Ratings” also.

Cheers,

Mike.

Coordinator
Jan 22, 2011 at 12:36 AM

Yes, you're right ... you can use the Recent Posts control.  Here's some markup for that:

<%@ Page Language="C#" %>
<%@ Import Namespace="BlogEngine.Core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Recent Posts</title>
</head>
<body>
	<blog:RecentPosts runat="server" />
</body>
</html>