This project is read-only.

customizing category output and search output

Topics: ASP.NET 2.0, Business Logic Layer
Mar 13, 2011 at 11:38 PM

Can someone tell me what pages/files i would need to edit if i want to change the formatting of the category page? By that, i mean the formatting of the page when you click on a category on the home page. I'd basically like it to look the same as the archive page formatting. 

similar question for the search results page - i found search.aspx and i see it's using a repeater. but what data fields are available for me to use? are there any additional fields or are the fields already on the page (title, link, description, content, type). If i want to add additional fields, what code would i need to look at?

In a nut shell, i basically want all the pages that list out the blog posts, to look like the postview that i have for ServingLocation.PostList. The archive page already looks the way i want. I need to adjust the category and search result page to look the same now.

Mar 15, 2011 at 7:56 AM


Mar 15, 2011 at 11:09 AM

When the URL is like /category/some-category.aspx, that's using the same default.aspx as the normal homepage.  The only difference is that the list of posts displayed is filtered for that category.

One thing you can do is within your PostView.ascx, output something different if the posts are "by category".  There's 2 ways (or more) to determine if the posts are "by category" from PostView.ascx.  One way is to pass in a property from User controls\PostList.ascx to your theme's PostView.ascx.  There's actually a property available that you can pass to PostView.ascx (it's currently not being passed in).  In User controls\PostList.ascx.cs, in BindPosts() is the code shown below.  I added the highlighted line -- and this is for BE 2.0, btw.

foreach (Post post in visiblePosts.GetRange(index, stop))
	if (counter == stop)

	var postView = (PostViewBase)this.LoadControl(path);
	postView.ContentBy = this.ContentBy;
	postView.ShowExcerpt = ShowExcerpt();
	postView.Post = post;
	postView.ID = post.Id.ToString().Replace("-", string.Empty);
	postView.Location = ServingLocation.PostList;
	postView.Index = counter;

Add that highlighted line shown above.  Then in your PostView.ascx file (in your theme folder), you can add code like this:

<% if (this.ContentBy == BlogEngine.Core.ServingContentBy.Category) { %>
	this post is part of a "by category" listing.
<% } %>

The possible values for "ContentBy" (for reference) are:  Unspecified, AllContent, Tag, Category, Author, DateRange, Apml.

So as you can imagine, you can output a completely different block of HTML for posts when they are "by category".

.... for the Search page, there are 3 types of items that might be bound to the repeater ... (1) Post, (2) Page or (3) Comment.  All 3 item types implement IPublishable, which is the type that the Search engine returns.  The properties for each IPublishable item are:

AbsoluteLink, Author, Categories, Content, DateCreated, DateModified, Description, Id, IsPublished, RelativeLink, Title, IsVisible, IsVisibleToPublic.

So you can output any of those values in the repeater.  Technically you could interrogate each item to determine if it's a Post, Page or Comment, and then based on that, cast the item to that specific type and extract additional information from it.

So in the repeater in search.aspx, you could add things such as:

... etc ...

Mar 15, 2011 at 7:35 PM

Very cool! thank you for all that info. So i should be able to easily customize the formatting of both the tags and category pages using the postview control - i can basically just completely re-use the code i already have there and just apply it to ServingContentBy.Category and ServingContentBy.Tag

The search might take a bit more work if i want the results to look like my postview postlist - especially since it's including things besides just posts. I'll probably have to compromise a bit on that one since my postlist doesn't include comments. But i should be able to get it close to what i want.

Thank you for your help. I'm going to try implementing this later today.