Cool thing about open source is sharing. You give some - you get some. When it comes to themes, there are tons of great free designs out there on the web for applications like blogs. Some of them are generic CSS templates, others specifically designed for popular open source projects like WordPress. This tutorial is about converting WordPress theme to BlogEngine, but most of it very much applied to almost any web template in the universe.

First, lets get to know what exactly we need to build BlogEngine theme. Thankfully, not a whole lot - all you really need is to create a new folder under ~/themes and add three files with few lines of code:

// site.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="site.master.cs" Inherits="site" %>
<html>
 <head id="Head1" runat="server"></head>
 <body>
   <form id="Form1" runat="Server">
     <asp:ContentPlaceHolder ID="cphBody" runat="server" />
   </form>
 </body>
</html>
 
// postview.ascx
<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="false" Inherits="BlogEngine.Core.Web.Controls.PostViewBase" %>
<h1><a href="<%=Post.RelativeLink %>"><%=Server.HtmlEncode(Post.Title) %></a></h1>
<asp:PlaceHolder ID="BodyContent" runat="server" />
 
// commentview.ascx
<%@ Control Language="C#" EnableViewState="False" Inherits="BlogEngine.Core.Web.Controls.CommentViewBase" %>

If you run you blog now and select theme with the same name you just gave to the folder, your new "theme" will work. It won’t look pretty, but you’ll see your posts and will be able to navigate to the details page and make comments etc. just fine.

From this example you can see that only things required in the theme are couple placeholders where BlogEngine will put generated content and couple tags like "head" and "form". That means, we can pretty much take entire Html from any template, put it in the site.master, stick placeholder in the corresponding gap - and we have our custom-built theme ready to go... well, almost :)

So, lets start by downloading WP theme. As example I'll use this tutorial theme. If you open archive and look inside, there are usually lots of .php files, images and few .css files. Delete all php's - you won't need them. Instead, go to demo site and open it up in the browser, right click and select "source code". Create html page in you theme folder and copy source code there. Make another copy - you'll use it as a reference if you accidently break something . Now run your project and go to html page, make sure it looks exactly as in the demo site.

When you look at the souce code you copied, there are a lot of hard coded content in there. Make it as uncomplicated as it gets by removing all content. Also, replace all web references with local ones. You'll get something much more manageable:

<html>
<head>
 <title>Tutorial Theme</title>
 <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
 <div id="left">
   <div id="logo"><h1><a href="#"></a></h1></div>
   <div id="navigation">
       <ul id="menu">
       <li class="current_page_item"><a href="#">Home</a></li>
       <li class="page_item"><a href="#">About</a></li>
       <li class="page_item"><a href="#">Blog Oh! Blog</a></li>
       </ul>
   </div>
   <div class="content">content</div>
 </div>
 <div id="right">Right sidebar</div>
 <div class="clear"></div>
 <div id="footer"><p><a href="#">Footer</a><br /><br /></p></div>
</div>
</body>
</html>

Now we are getting somewhere. Copy everything inside “body” tag into site.master page and replace content div with ContentPlaceHolder. Run your project and you’ll see that site looks much better. A little more patience and it will look like the picture below. In the next part I’ll show you how to reconcile CSS that comes with template and BlogEngine specific elements and we look at some tricks you can use building your custom theme.

Signature

People are arguing about which layout is better since web exists. Some like it fixed, others prefer it fluid (or elastic). I always used fluid layouts, mostly because I really hate to see narrow column with unreadable small text on the screen with large resolution - and I used to see it a lot. Naturally - large companies going after broad audience don't want to alienate even tiny portion of potential customers and always go with lowest common denominatorW. Lately, though, I start noticing these ugly sites disappear. To confirm my guess, I went to Google analyticsW for my blog and looked at screen resolution for clients that access this site. Wow... you guys! More...

Signature

Just read a great article at coding horror on becoming a good blogger. It says that it takes at least a year to even get noticed and main peace of advice is to keep punching and feel good about it. Well, it sounds… hmmm… encouraging. Thanks God I’m not aiming that high. Anyways, I decided to follow advice and throw a punch – even though my new shiny theme for BlogEngine is not quite ready yet and I was hoping this will be my next subject. Funny how it goes – takes about an hour to convert any CSS template into BlogEngine theme, this is how simple it is and how good ASP.NET overall and BlogEngine in particular implemented skinning. Almost too good to be true – and it isn’t. Dirty little secret is that it takes ten times more to polish it to the dissent “production” state, when it looks good in all major browsers and scales fine for reasonable range of screen resolutions. I’ve heard that there are about ten testers for every developer in Microsoft – totally makes sense! More...

Signature

There are two important things to understand when dealing with CSS - how to address element you are styling and why in the world it does not picking the style you are trying to assign it. For the first part you might consider to install add-in to your browser, there are many for FireFox and IE alike, so that it will actually show element address for you.  For example, Developer Toolbar for FF can show you full path to tag cloud link in the browser panel like shown in the picture. The second important thing to remember is that CSS called "cascading" for a reason: all styles down the road will cancel those on top. Which is a good thing - this way you can style all anchors first and then be able to override style for the second layer anchors canceling some attributes, keeping others and yet adding some on top.  And this is what we generally doing here: first level menu buttons have it's own style, sub-menus keep some of the attributes and cancel others so that sub-menus look different.  To overcome browser incompatibility we will add conditional block to the header of the page: More...

Signature

When you are a developer working with CSS on “as needed” bases, you have to be prepared for some pain and frustration. Don’t get me wrong, I love CSS – and what not to love? It makes your HTML code clean and light-weight, pages load faster and all formatting logic neatly separated from presentation markup. Beautiful! But I hate it, too. There are two major problems with CSS: it is not intuitive and every browser has its own parser doing job “better” (differently) than others. Practically, it means that when working on CSS you have to fire up 3-4 different browsers and test every line as you go. More...

Signature

Lately I’ve been working on the new cool theme for BlogEngine that I’m going to share with community. One of the tasks is to let it be more content oriented, which is a bit different then other themes. Basically, it comes down to having good navigation menu that will allow you to utilize stand-alone pages in BlogEngine to its full potential. Currently, you have a choice to make page a “child” of the other page so that pages do have hierarchy and can be nested into the tree-like structure. It just not rendered by BlogEngine this way, at least not right now. To make it happen I used code published on the BlogEngine forum, just making a few changes to fit my needs. This is a simple control that looks inside core library and renders all BlogEngine pages into unsorted list. Then, you can just add it to your theme and here you have it: More...

Signature
<<  May 2008  >>
SuMoTuWeThFrSa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Enhanced with Snapshots

Subscribe to Rtur.net