This project is read-only.

Can you insert a PostList in page?

Topics: Controls
Feb 14, 2011 at 2:37 AM

I have a page that needs to be avialable as a "parent" page. I also need this page to show a postlist.

Is there anyway that a page (a page added in the control panel) can include a postlist?




Feb 15, 2011 at 6:29 AM

Or is there anyway to get a custom page to show up in the page list? So it can be selected as a parent?


Feb 15, 2011 at 11:45 PM

Any thoughts?

Feb 17, 2011 at 3:16 AM

In a Page (or even a Post), you can inject a user control.  PostList (PostList.ascx in the User Controls folder) is a user control.  However PostList doesn't generate a list of posts itself ... it only accepts a list of posts passed to it.

You can create a new user control that is a wrapper for PostList.  It can pass a list of posts to PostList.  And then from your Page, you can inject the new user control into it.

To give an example, create a new file named "posts1.ascx" and place it in the User Controls folder.  The contents of posts1.ascx is:

<%@ Control Language="C#" %>
<%@ Import Namespace="BlogEngine.Core" %>
<%@ Register Src="~/User controls/PostList.ascx" TagName="PostList" TagPrefix="uc1" %>

<script runat="server">

	protected void Page_Load(object sender, EventArgs e)
		PostList1.Posts = Post.Posts.ConvertAll(new Converter<Post,
			IPublishable>(delegate(Post p) { return p as IPublishable; }));


<uc1:PostList ID="PostList1" runat="server" />

Then in your Page, you can reference the user control (i.e. inject it) by adding the following into your Page in the WYSIWYG editor:

[usercontrol: ~/User Controls/posts1.ascx]

When you save the Page, and view it, you should see the list of posts.  You can tailor the above code in Page_Load to only show a subset of the posts ... depending on your needs.

Feb 21, 2011 at 2:59 AM

THANK YOU! Sorry it took me so long to get back to you. I just got this working tonight, and it works great, exactly what I need. Thanks!!!!