by Bobbi Perreault
18. September 2009 00:23
Share on FacebookI've used BlogEngine.Net for a CMS a few times now and I'm happy with the way it has worked out for the very small business sites that I maintain. I'm comfortable in this programming environment and so that's why I choose it over WordPress.
Its easy to modify so that each BlogEngine.Net category is directed to a separate page. So, in the case of one of my customers when they want a news page that they can update and also a tips page that they can update – I set it up like this. Create a category called news and a category called tips in the Admin area.
Here's how I set it up. In the [User controls] folder is a control called PostList.ascx. I added a property to this control called PageCategory.
Here's the code from the .aspx page which will set the PageCategory properly for the page:
<%@ Register Src="User controls/linksSide.ascx" TagName="linksSide" TagPrefix="uc2" %>
<%@ Register Src="User controls/PostList.ascx" TagName="PostList" TagPrefix="uc1" %>
<%@ Import namespace="BlogEngine.Core"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divError" runat="Server" />
<uc2:linksSide ID="LinksSide1" PageCategory="cleaningtips" runat="server" />
<uc1:PostList ID="PostList1" PageCategory="cleaningtips" runat="server" />
</asp:Content>
Here's the code which implements the PageCategory property inside of PostList.ascx.
Basically, it all comes down to making sure the only posts which display are those which match the category.
( Linq would work great on this)
foreach (Category cat in Category.Categories)
{
string name = cat.Title;
if (name.Equals(PageCategory))
{
List<Post> visiblePosts = cat.Posts.FindAll(delegate(Post p) { return p.IsPublished; });
if (Posts == null || visiblePosts.Count == 0)
{
hlPrev.Visible = false;
hlNext.Visible = false;
return;
}
else
{
hlPrev.Visible = true;hlNext.Visible = true;
}
LoadAll(visiblePosts);
break;
}
}
