This project is read-only.

Common Text at top of category and each post in that category

May 26, 2010 at 9:57 AM
Edited May 26, 2010 at 10:09 AM

Hi Guys,

I have a situation where I'd like to put some common text at the top of a category, and at the top of each post within that category

e.g. If viewing the category below I'd like the disclaimer in red to appear once. It is currently in one of the posts but I really need it in the category page - maybe in a separate div

And then if I view an individual post - it would need to go again at the top of the post ?

Any pointers - preferably in the theme if this is possibloe

Many thanks


May 26, 2010 at 12:28 PM

In the PostView.ascx file (in your theme folder), at the top (right above the first <div>), you can add:

<% if (Location == BlogEngine.Core.ServingLocation.SinglePost &&
   Post.Categories.Find(delegate(BlogEngine.Core.Category c) { return 
   c.Title.Equals("RSI Stretches / Exercises", StringComparison.OrdinalIgnoreCase); }) != null) { %>
    Disclaimer when viewing an individual post for this category.
<% } %>
And then in default.aspx (in the root folder), probably above the <h1> (or around it), you can add:

<% if (Request.RawUrl.StartsWith(BlogEngine.Core.Category.Categories.Find(
   delegate(BlogEngine.Core.Category c) { return
   c.Title.Equals("RSI Stretches / Exercises", StringComparison.OrdinalIgnoreCase); }).RelativeLink,
   StringComparison.OrdinalIgnoreCase)) { %>
    Disclaimer on the homepage at the top when viewing this category.
<% } %>

May 26, 2010 at 2:40 PM

excellent - thanks Ben - I'll give it a go !


Jun 4, 2010 at 8:22 AM

Hmmm - OK it works great on the individual post pages - but I can't see where to put the code in default.aspx

The markup looks like this :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="_default" %>
<%@ Register Src="User controls/PostList.ascx" TagName="PostList" TagPrefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphBody" Runat="Server">
  <div id="divError" runat="Server" />
  <uc1:PostList ID="PostList1" runat="server" />
  <blog:PostCalendar runat="server" ID="calendar"
    Width="100%" />    


Thanks v much



Jun 4, 2010 at 11:43 AM

I would put it right above the following line of markup.  (the following line of markup contains the list of posts)

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

Jun 4, 2010 at 11:52 AM

Thanks - I tried that but get the error as below :(


Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'BlogEngine.Core.Category' does not contain a definition for 'RelativeLink'

Source Error:

Line 7:    <% if (Request.RawUrl.StartsWith(BlogEngine.Core.Category.Categories.Find(
Line 8:     delegate(BlogEngine.Core.Category c) { return
Line 9:     c.Title.Equals("RSI Stretches / Exercises", StringComparison.OrdinalIgnoreCase); }).RelativeLink,
Line 10:    StringComparison.OrdinalIgnoreCase)) { %>
Line 11: 


Jun 4, 2010 at 9:39 PM

Oops, I see.  I was using code available in BE 1.6, and didn't remember that wasn't available in BE 1.5.

To make it a bit easier, in default.aspx, if you could add the following at the top as the 3rd line (below <%@ Register ...)

<%@ Import Namespace="BlogEngine.Core" %>

Then, the updated block of code is:

<% if (Request.RawUrl.StartsWith(Utils.RelativeWebRoot + "category/" +
   Utils.RemoveIllegalCharacters(Category.Categories.Find(delegate(Category c) {
   return c.Title.Equals("RSI Stretches / Exercises",
   StringComparison.OrdinalIgnoreCase); }).Title) +
   StringComparison.OrdinalIgnoreCase)) { %>
    Disclaimer on the homepage at the top when viewing this category.
<% } %>

Jun 7, 2010 at 12:31 PM

Excellent - thanks very much !!!

That works perfectly !

I've raised another query on this thread - don't suppose you have any suggestions about how I could solve this issue ?

Thanks Again !