Quantcast
Channel: On Web Usability - ASP.NET
Viewing all articles
Browse latest Browse all 3

How I modified a WordPress theme to work with BlogEngine

$
0
0

The title I was going to use for this post was “How to convert a Word Press theme to a BlogEngine theme”. This blog uses BlogEngine (BE) as the blogging engine. Due to the lack of quality themes for BE, I decided to use a WordPress (WP) theme. I thought I would just be able to convert the theme to a BlogEngine theme and be done.

WordPress is written in PHP which resembles classic ASP where the code is interlaced with the HTML. I expected a WP theme would just be a bunch of HTML, CSS & Javascript files like most web site templates. It turns out that a WP theme could include a lot of PHP code. The strength of a WordPress theme lies in its ability to extend WordPress’s default functionality by adding extra options and workflow. When I looked at the theme I wanted to use with BlogEngine, I noticed all the PHP code which define what and how things display in the web page.

My first expression was that the task wasn’t going to be a straightforward conversion. My first attempt was trying to understand what the PHP was doing. Although I didn’t have experience in PHP, the code is pretty easy to read and understand. At least it’s not Perl whose syntax I hate! The problem was the code wasn’t easy to follow. The code is in many files and functions are calling other functions which are scattered in several files. I needed to trace and step through code and have breakpoints. What do PHP developers use as an IDE? First thing I did was check JetBrains.com and examine their PHP offerings. I know they develop good IDE’s and I LOVE their Resharper tool. I found an IDE called PhpStorm.

I set up a php develpment environment on my Windows box. Installed PHP under IIS. Installed WordPress and unzipped the theme in it and activated the theme. Installed phpStorm and the first thing I did was look for the debugger. PhpStorm doesn’t come with a debugger of its own! Not like Visual Studio. You have to download and install a third party debugger extension. I used xdebug. I had to do some configuration tweaks and finally got it working with breakpoints and single stepping. Cool! I actually thought that there’s no PHP IDE which works like Visual Studio. After trying to follow the PHP code I came to the conclusion that this is going to be a ton of work. Converting the theme and code into .NET, user controls and trying to also understand how BlogEngine theming and code works. Getting dissapointed now. So I scrapped this method.

I decided to use a completely different approach. I am actually only interested in the layout produced by the theme. Just the HTML and CSS. So I decided to let PHP do its work and just grab the page’s html & CSS source. However I also need to understand how BlogEngine theming method works. I read the theme documentation and got a good idea of the different user controls. So I grabed the html source and converted it into a master page minus the main content. The different sections on the right side are made by different BE widgets. I modified them a bit to use the WP theme. WP has a similar concept of widgets but I just grabbed their html as well and plugged into The BE widgets. BlogEngine’s posts and comments reside in user controls. I modified these controls to use the WP theme html and css classes as well. What I did is completely ignored all the PHP code and just get the actual layout. I used Firebug to find which CSS classes where used and copied them over to BE. I noticed a lot of the CSS attributes where not used in the HTML tags. The theme needs to be cleaned.

While BlogEngine does support themes, the themes are not isolated and do not work without supporting code. There’s code in BlogEngine which spit out css and html. I didn’t like this about BE where they have things hard coded like that. There was no way to fit the WP theme without modifying BE’s code or at least not for the theme I am using. I am guessing the reason why all BE themes resemble each other is because of the theme bounderies and limitations BE imposes on the theme developer.

I managed to get the theme and BE working together. The result, and probable issue, is that I won’t be able to do an inline BE upgrade because of all the custom code. This might not be a big issue because blogging software do not change often. If the next upgrade does have a functionality I need, I will take it apart and plug manually into my system. The most challengin part was the threaded comments. A reply to a reply will actually display under the reply with some indentation. I added an anti comment spam technique and eliminitated the use of a captcha. I will explain what I did in a future post.

I did encounter a bug in BE where it breaks all the CSS conditional comments. I reported the bug and a BE developer released a newer version.


Viewing all articles
Browse latest Browse all 3

Trending Articles