a few basic(?) BlogEngine.NET questions

Feb 9, 2010 at 3:04 AM

Hello friends,

I have successfully installed BlogEngine.Net 1.5 (web version) onto my site in the /blog subfolder.  I like it, but have a few questions.  If you can answer any of them I would really appreciate it! 

1)      When a list of posts appears on a page such as blog/BlogEngine.Web/category/mycategory.aspx the title of each post gets an <h1> tag.  I believe this is bad SEO practice, isn’t it?  I thought there should be only 1 <h1> tag for a page.  I would like to simply add the category name as the <h1> tag for the entire page, and make the titles of the posts <h2> tags.  How would I go about doing this?

2)       Are my modifications/customizations restricted b/c I used the web version?  I would think that I’d want to use the source code version for customizations, but I read on the BlogEngine documentation: “Source Code: This is the developer option. If you are interested is seeing how things work or want to add to the functionality, this is your option. Note that although you can look at the source with Visual Studio 2005 Express, you can't rebuild the DLL with it.” I can’t rebuild the dll?  Btw I had some luck changing postlist.ascx.cs and postview.ascx files without rebuilding/recompiling anything.  And that was using the web version! 

3)      For mazimum seo, shouldn’t keywords that appear in the blog entries hyperlink back to pages on the main web site?  For example, if my business is about dogs, and I have “dogs” all over the main web site, and I even have a page “dogs.aspx”, shouldn’t my blog entries hyperlink back to the main site’s dogs.aspx page?

4)      Optional question:  where would I look in the BlogEngine code to understand how pages are built dynamically?  Isn’t there a page handler that fulfills the requests for pages such as BlogEngine.Web/Category/Dogs and BlogEngine.Web/2010/2, etc.?

 

Thanks in advance,

Will

 

Coordinator
Feb 9, 2010 at 8:15 AM

Hello, welcome.

1.  You can edit the <h1> tags in the PostView.ascx file in the themes folder (e.g. themes\Standard).  Each post displayed (even when displaying the posts for a category) uses this PostView.ascx file.  You can change <h1> to <h2> in this file.

2.  With VS 2005 Express edition, it looks like you couldn't build/compile class libraries.  But this is no longer true with VS 2008 Express Edition.  You CAN build and recompile to create a new DLL (source).  The best one to get would be the Visual Web Developer 2008 Express Edition which has support for both web type projects, as well as being able to build DLLs.  Being able to make changes in the core can be very handy at times.  But a lot of the markup is outside of the core -- as you noticed.  The theme folder contains quite a bit of the markup.  The User Controls folder too.  Same with the Widget and App_Code\Controls folder.

3.  Feel free to hyperlink each of your keywords :)  The tags and categories you assign to a post ARE hyperlinked.  But the words within each post are not automatically hyperlinked.  However, this type of functionality can be created via Extensions.  An extension can modify the post content as it's being saved, or modify the post content as it's being served to a browser.  Examples of each are in some of the Extensions that come with BE (App_Code\Extensions).  There may already be a BE extension which does this (not sure).  But if not, an Extension could be created to parse the body of the blog post (when it's being saved or served to the browser) and hyperlink words you want hyperlinked.

4.  In the BE core, in the Web\Modules folder, there's a file named UrlRewrite.cs.  This takes care of a good deal of rewriting URLs.  The default.aspx.cs page in the root of the blog will receive or see the rewritten urls, and output the relevant content.  So UrlRewrite.cs and default.aspx work hand in hand.  Also, in the BE core, in the Web\Controls folder there is a file named BlogBasePage.cs.  This does things such as dynamically setting the master page (aka theme) based on the theme you have set in the Settings.

Feb 9, 2010 at 2:24 PM

Thanks a lot for the response Ben. just one followup:

1) Yes, I had good luck changing postview.ascx, and postlist.ascx.cs as well.  But I don't want to change all of the <h1> tags to <h2>.  I want just one <h1> tag at the top of the document that will contain the page title, not any of the post titles that are currently <h1>.  That's why I think I need to fix this at a higher level than postview.ascx or postlist.ascx.cs. 

Will

Coordinator
Feb 9, 2010 at 6:19 PM
Edited Feb 9, 2010 at 6:20 PM

The markup in PostView.ascx is for each post.  The H1 can be put into the PostList.ascx file (in the User Controls folder) .... or in the default.aspx page in the root of the blog.  PostList is what creates a new PostView for each post ... it's used when displaying the homepage posts, or the posts for a particular category, tag, author, date range, etc.  The hierarchy basically looks like this:

site.master (theme folder, used to display everything except for admin area -- site navigation, contains <head> tag etc)
.......... post.aspx (root of blog, used to display an individual post)
....................... PostView.ascx (theme folder, it represents a single post)
....................... CommentView.ascx (User Controls folder, it displays the Comment entry form, and displays each comment)
........................................ CommentView.ascx (theme folder, it represents a single comment)
.......... default.aspx (root of blog, used to display homepage posts, posts for category, tag, etc)
....................... PostList.ascx (User Controls folder, it displays the list of posts)
........................................ PostView.ascx (theme folder, it represents a single post)
.......... page.aspx (root of blog, used to display BE "Pages")

Feb 10, 2010 at 2:12 PM

thank you so much for your comments Ben.  I will convince myself of the page handler operation today.  :-)  Take care,

 

Will

Feb 11, 2010 at 3:54 AM

Hi Ben,

  I've been working all day on this, and still have some issues-

1) How would I go about changing the sort order for my posts (instead of having the newest one on top, have the oldest on top)?

2) After a lot of investigation, I still am not finding a section of code that I was thinking would exist.  Something like:

a) Write the header info

b) Write the data grid of posts info

c) Write the nav links on the right (date, category, etc.)

d) Write the footer info

 

Because, if I am going to insert a header for the page in with an <h1> tag, I want to insert this text between a) and b) above.  But BlogEngine doesn't seem to be written in such a format.  Is it possible to insert such a header?

Thanks for your help,

Will

Coordinator
Feb 11, 2010 at 5:20 AM

For inserting an <h1> tag (or anything else), I would do it in default.aspx.  In default.aspx, I added this bolded line:

<h1 id="h1" runat="server" visible="false"></h1>
<uc1:PostList ID="PostList1" runat="server" />

By default, the <h1> is not visible (not served to the browser).  In default.aspx.cs, you can turn it on and set the content at any time.  Maybe you only want to show the <h1> in certain conditions, for example.  In default.aspx.cs, in DisplayCategories(), I added these two bolded lines of code to turn the <h1> on and set the content.

Page.Title = Category.GetCategory(categoryId).Title;
h1.Visible = true;
h1.InnerHtml = Category.GetCategory(categoryId).Title;

For sorting the posts the other direction (oldest first), there's a few ways to do this.  In PostList.ascx.cs in the User Controls folder, in BindPosts(), you can add the bolded line below, which will sort the posts the other way:

List<IPublishable> visiblePosts = Posts.FindAll(delegate(IPublishable p) { return p.IsVisible; });
visiblePosts.Sort(delegate(IPublishable p1, IPublishable p2) { return p1.DateModified.CompareTo(p2.DateModified); });

Feb 11, 2010 at 4:34 PM

Great, thanks for the feedback-  I'll see if I can't tame BE yet!

 

Will

Dec 15, 2010 at 10:45 PM

I had the same question about controlling the number of H1 tags on the page. I was thinking of a different tactic - is there a value in the Post class (that is visible within the PostView.ascx file) that I could use to determine if a post were the first on the page, or if it is the only post on a page?

There is, in fact, a variable right there on the page that can be used to this effect. In the PostView.ascx file, I replaced this line:

<h1><a href="<%=Post.RelativeLink.Replace("MattLindley/", "") %>" class="taggedlink"><%=Server.HtmlEncode(Post.Title) %></a></h1>

with this:

<% if (Index == 0)
     { %><h1><%}
     else
     { %><h2><%} %><a href="<%=Post.RelativeLink.Replace("MattLindley/", "") %>" class="taggedlink"><%=Server.HtmlEncode(Post.Title) %></a><% if (Index == 0)
     { %></h1><%}
     else
     { %></h2><%} %>
Since every page of posts starts with an Index of 0 and Index increases by 1 for each subsequent post on the page, this test will use h1 for the first post on the page, then uses h2 for all subsequent posts. Easy.