Using SyntaxHighlighter to Format Code in WordPress

Based on a question in the StackOverflow beta site, I did some quick research into what are the best ways to perform syntax highlighting on code that is posted on blogs. Among the methods that were suggested (by myself or others):

  1. Hack together your own display logic to format it as you see fit
  2. Use the SyntaxHighlighter JavaScript library
  3. Use Windows Live Writer with the Insert Code plugin (I discuss that here)
  4. For WordPress, use the WP-Syntax plugin

Coincidentally, I had heard Scott Hanselman talking about how he does code formatting just a couple of days ago, in Hanselminutes #125, where he described how he posted code on his blog by putting it inside <pre></pre> tags, adding specific name and class attributes, and letting some JavaScript library do the formatting work. So I went to his blog, opened up a post with some code, and found my way to the SyntaxHighlighter JavaScript library. This is a very nifty library that handles formatting very nicely for a number of popular programming and scripting languages, and seemed to have a very easy implementation. So I decided to implement it for formatting code on my site.
Continue reading

Setting up a Customized Blog in 7 Easy Steps

When a person chooses to create a new blog, there are two routes to choose from: you can use one of the popular hosted blogging services (like Blogger or WordPress.com) or you host the blog yourself. The first option is definitely the easiest – someone else worries about all of the blog setup, database issues and hosting. You just put up the content. The second option however gives you more flexibility and control over the domain name, blogging software, plugins, advertising and template customization. However, when you set up the blog yourself, you become responsible for all aspects of its operation, a somewhat daunting proposition.

A couple of days ago I created a blog from scratch (Telecommuterer.com). I would like to review all of the different steps that went in to this. All told, it took about two hours to go from nothing to a fully functioning blog with initial content posted. Though it is more difficult than using a hosted blog service, I think that if you would like to use your blog for anything more than casual use and you are up to the task, in the end it is worth it to invest a little bit of time and money in setting up the blog by yourself.

I am assuming here that you already have the concept for the blog in place and a general idea of the types of content you would like to host. I will describe the process using blogging software from WordPress.org as I think it is the best free software available for the task (with easy setup, great plugin and community support).

  1. Get a Domain Name – Get a domain name for your blog. I use Go Daddy for all of my domain name purchases (though there are thousands of other providers that can do the same for you). For Search Engine Optimization (SEO) reasons, the shorter the domain name, and the closer it is connected to the main topic of your site, the better. If your first choices are taken, there are several services that will take your keywords and return a list of available names that might be good, like DomainsBot, DomainTools and DomainIt.
  2. Set Up Hosting – Set up your hosting for the website. The main requirements are that that you use LAMP (Linux, Apache, MySQL, PHP) based hosting. There are thousands of services out there that will do this for less than $15 per month. If you are using a service that is not well known, I highly recommend checking out their reputation on the web before using them. I personally use MediaTemples (gs) GridServer service and DreamHost for my personal and client sites and would have no reservations recommending them to others.
  3. Connect Your Domain – Set up a new Website at your webhost (they should have instructions on how to do this). Your host will give you their NameServer (or DNS) information. (This normally takes the form of something like ns1.hostname.com and/or an IP address). Take this information and go to the site where you bought your domain. On this site, in your domain management, change the Nameservers (or DNS settings) of the domain name to that which was given to you by your Web Host. After you do this, your domain name will now be connected to your website that is hosted on the servers of your Web Host.
  4. Install WordPress – Many hosting services have tools that will do this automatically via server-side scripting. If that is available and they offer it with the most recent version of WordPress (currently 2.2), go for it. Otherwise, you can do it yourself in a few easy steps
    1. Download the most recent version of WordPress
    2. Extract the files from the zip or tar.gz file onto your computer. Upload them to your web host servers using FTP
    3. Using phpMyAdmin or whatever other database control interface your web host provides, set up a new mySql database for your site.
    4. Follow the rest of the instructions on the WordPress 5 Minute Install page (it really does take just five minutes)

    After going to the /wp-admin/install.php page on your site and following the instructions there, you should have a working WordPress blog set up on your domain name with the default template in place (and absolutely no content). Log into your admin section (you may want to bookmark the page at /wp-admin/ on your site), go to the Options section (and its different subsections) to set up your blog settings as you would like (don’t forget to set Permalinks if you have the capability and want to use them to create nice-looking urls for your posts.

    Now the real fun begins.

  5. Set Up the Theme – If you are a real web-design pro and an expert with WordPress who can design their own theme from scratch, this doesn’t apply to you (and you don’t need to read any of this anyway). Otherwise, you should pick a theme for your site. There are hundreds of free WordPress themes out there to choose from. I recommend starting at the WordPress Themes viewer. It allows you access to test-drive hundreds of free themes and you can search based on features of the theme, layout options, etc. If it is too overwhelming, try filtering by theme features, using the list of most-downloaded themes (on the side of this page) or some of the themes featured here. When you have chosen a theme, download it to your computer and upload the files to your /wp-content/themes folder on your site. Go to the WordPress Admin > Presentation, and select your new theme.
  6. Customize the Theme – If you are scared of CSS and HTML and are completely satisfied with the way that the theme works, you can skip this step. Otherwise, it is advisable to go into your theme files and customize sections of it. This is done to differentiate the look and feel of your site from other sites that may be using the same theme, as well as to change the locations and look of elements of the theme to suit your specific needs.Any customization work that you will do will take place in the different theme files, found in /wp-content/themes/theme_name/. The files that you are most likely to change are header.php, footer.php, sidebar.php, index.php and single.php for content and styles.css for style changes. You can read about the different types of theme files, how they work, template tags and pages, customizing templates and more on the WordPress Codex and Support forums.The potential for changes is practically endless. To give some ideas of things to change here is a list of changes that I made on my new site
    • I changed made the font size larger for all content text
    • Removed “sponsor links” on the theme that were pointing to indecent sites (see Matt’s essay on this for more info)
    • Changed the RSS links to Feedburner feeds, added an Email subscription link (through Feedburner). Moved these links to higher on the page
    • Changed some of the default, hard-coded text on the page
    • Added some tags that had been left-out by the theme author (go to next page/post, etc)
    • Changed the format and information displayed in the post info section on both the main page and the single post page
    • Added links to stats tracking services (I use both StatCounter and Google Analytics)

    Some other things you might want to change in the theme to really change the look of it is the header image, background colors, link colors and other visual elements. As you are changing the template files, upload them to your site to check on how your changes look and make sure that you haven’t broken anything.

  7. Set up Plugins – As with the previous step, if you are completely satisfied with every aspect of your blog performance, you can skip this step (just remember to enable the Akismet anti-spam plugin that is included with the software). However, it is worth exploring the world of plugins if there is anything that you want to on your site that is not included by default or with the standard template tags. To set up any plugin, download its files, upload them to the /wp-content/plugins/ directory on your site, follow any specific directions that may be given with the plugin, go to the Plugins page in your site and enable the plugin. Some plugins work automatically in the background, some will require you to add tags to your template files (they should give instruction on how to do this).Plugins are hosted all over the internet, often on their author’s websites, and sometimes in centralized repositories. If you are in need of specific functionality, try searching for it (using keywords “[functionality] wordpress plugin” should give you some results if the plugin exists). Otherwise, try looking in some of the online repositories to get an idea of what is out there. Here is a list of the plugins that I used on my new site:

    Plugins can add lots of powerful functionality and totally change the way that you use your blog. They are one of the strongest features of WordPress and I highly recommend taking a look at what they have to offer.

You are now done setting up your blog (though as you use it more, you may decide to change are the template some more and add more plugins). Now all that’s left to do is to start adding content. Good luck!

WP: Mint Popular Posts

Mint Popular Posts is a WordPress plugin that for use in conjunction with the Mint. Mint is a php/mysql stats program that stores data (by default) in tables in the same DB that you would use for WordPress. Thus a WP-plugin to access the stats table and return a list of the most popular posts. Continue reading