WP Plugin: Code Viewer

Code Viewer is a WordPress plugin that pulls source code from an external file and displays it, optionally adding a link to download the code directly. The plugin displays the code with proper indentation, line numbers, and automatic long-line wrapping.

When using Code Viewer, you no longer have to worry about typing countless entity references in order to make your code “HTML friendly” or to simulate tabs…it’s all done automatically with PHP and a little CSS. By inserting line numbers on your page, the plugin also eliminates the problem of long, non-breaking lines screwing up your layout. In addition, line numbers make convenient reference points when discussing code samples.

Last, but not least…because you’re pulling the source code from an external file (rather than having it embedded directly in your entry), the same code can be repeated on numerous pages, and you only have to type it in once. This not only saves you time, but when you update the code in the centralized file, all instances of that code will be updated along with it.

Installation

I am no longer maintaining Code Viewer, please see Current Status of the Code Viewer Wordpress Plugin for more details on where to get the latest version.

  1. Download Code Viewer v1.1
  2. Open the downloaded file in a text editor and configure the $default_path variable (found on line 12), setting it equal to the absolute path of your code folder
  3. Save the edited file
  4. Change the extension of the saved file from .txt to .php
  5. Upload the changed file into your wp-content/plugins/ directory.
  6. Activate the plugin on your WP Admin » Plugin Management page by clicking the corresponding “Activate” link under the Action column.

You’ll also want to add some new classes to your CSS that will control the look of the code listing. Everything (with the exception of auto-indention) works just fine without the CSS; but adding it in makes a huge difference on readability. Feel free to change these values to whatever you like, but this is how I have mine set up:

/* ---( CODE VIEWER FORMATTING )------------------------- */

ol.codelist {
    border: 1px solid #DDD;
    color: #C63;
    font-family: "Courier New", Courier, monospace;
    line-height: 130%;
    padding: 12px 12px 12px 45px;
    margin: 1.5em 0;
    }

ol.codelist li {
    margin: 0;
    padding: 1px 2px;
    }

ol.codelist li.tab0 { padding-left: 2px; }
ol.codelist li.tab1 { padding-left: 26px; }
ol.codelist li.tab2 { padding-left: 50px; }
ol.codelist li.tab3 { padding-left: 74px; }
ol.codelist li.tab4 { padding-left: 98px; }
ol.codelist li.tab5 { padding-left: 122px; }
ol.codelist li.tab6 { padding-left: 146px; }
ol.codelist li.tab7 { padding-left: 170px; }

ol.codelist li.odd { background-color: #FFF; }
ol.codelist li.even { background-color: #F0F0F0; }

ol.codelist li.sourcelink {
    color: #000;
    font: 115% Georgia, "Times New Roman", Times, serif;
    list-style: none;
    margin-left: -32px;
    padding-top: .85em;
    text-align: center;
    }

ol.codelist li code { color: #222; }

Usage

Code Viewer basically searches your entry for a custom XML tag named <viewcode />, that tells the server to look at an external file and parse it line-by-line into an ordered list. It can be placed anywhere a block-level tag is valid, and like any empty element in XHTML, the tag must be properly closed.

To better illustrate its usage, the tag used in this entry (to show the code-viewer.css listing above) was:
<viewcode src="2004/09/code-viewer.css" link="yes" />

Read More »

Workin’ My Backend

I’m under no delusions about the number of readers I have, and yet I feel compelled to write an update on how things are progressing. Call it hope for a self-fulfilling prophecy…after all, if I’m going to start a blog that I actually expect people to read, I have to write entries in it sooner or later, right?

It may look as though not much has changed around here over the past couple of weeks, but I assure you things are moving forward. Admittedly, I have been busy with school and my personal life, and consequently haven’t had much time to devote toward ElasticDog, but I haven’t completely ignored it either.

Not only have I started working on numerous entries, but I’ve also been teaching myself some PHP in an attempt to customize WordPress even further than I already have. Here’s a short list of some of the projects I’ve been tackling:

  • Convenient Code
    A WP plugin that pulls source code from an external file and displays the associated code with line numbers.
  • Faking Templates with WP
    There are about a billion different ways to do this, and I’ve come up with one of my own. With my method, I’m able to control what appears in both the main column and sub column of my site, differing each one for the home page, individual pages, and each of the three archive page types (yearly, monthly, and categorical).
  • Project JumpDrive
    How I found the road to USB flash drive heaven.
  • Additional CSS Inclusion
    A WP plugin that will allow you to include an additional CSS file for a specific entry. That way, you’re not forced to load a bloated style sheet for all of your pages.
  • Streamlining Code and Planning for Upgradeability
    Although this is a never-ending process, I’ve been going through my code, commenting important sections, simplifying structure, and adding more flexibility in preparation for inevitable updates.
  • Text Editor Showdown
    A no holds barred comparison between popular HTML & text editors.

That’s just a sneak peak at what I’ve got brewing over the next couple of weeks. I’ll also be adding the rest of the main site pages (about, portfolio, etc.) as soon as humanly possible. Simply put, there’s much more to come here at ElasticDog, and by the time I’m finished workin’ my backend, even Jennifer Lopez will have something to be envious of!

WP Plugin: Optimal Title

This plugin will soon be deprecated…see Optimal Title Functionality Now in WordPress Core.

IMPORTANT!!!

Due to recent XSS security issues fixed in WordPress 2.1.3, the code for Optimal Title also had to change in order to fix the vulnerabilities. It is recommended that ALL users of this plugin upgrade to version 3.0. Due to changes in how Optimal Title works, that should be the last upgrade you will ever need. For more details, see the update details section below…


Optimal Title is a WordPress plugin that mirrors the function of wp_title() exactly, but moves the position of the 'separator' to after the title rather than before. This allows you to have your blog name tacked on to the end of the page title instead of having it appear first.

Having your page information appear before your blog name in the title is advantageous because it provides more meaningful search engine results and browser bookmark names. The text that appears between your <title></title> tags is used to generate both of these things, and will often be truncated when viewed. Because of this, it is more effective to have words directly relating to the content of your page appear before common markers. Not only will the titles be more meaningful, but the they will also be more scannable when being viewed in a list. For more information on this concept, see Dr. Jakob Nielsen’s article Microcontent: How to Write Headlines, Page Titles, and Subject Lines.

Installation

  1. Download Optimal Title v3.0 and unzip the archive.
  2. Upload optimal-title.php into your wp-content/plugins/ directory.
  3. Activate the plugin on your WP Admin » Plugin Management page by clicking the corresponding “Activate” link under the Action column.
  4. Follow the usage guidelines shown below…

Usage

In your header.php file, replace the function call wp_title() with a call to optimal_title(). You’ll also want to position your blog name after your usage of Optimal Title in order for this to work as intended. You should end up with a line that looks something like this:

<title>< ?php optimal_title(); ?> < ?php bloginfo('name'); ?></title>

For a more complicated version that checks to make sure the plugin is installed and also includes support for a tagline on the home page, this is actual code I use on this site:

<title>< ?php if ( function_exists('optimal_title') ) { optimal_title('|'); bloginfo('name'); } else { bloginfo('name'); wp_title('|'); } ?>< ?php if ( is_home() ) { ?> | < ?php bloginfo('description'); } ?></title>

Read More »

A Fresh Start

I started the original ElasticDog about a year ago when I became interested in standards-based–web-design. The more I read about the subject, the more I wanted to try things out and to create a standards-based site of my own. It had been years since I had even touched HTML, but I was determined to do things right this time around. I stayed up late nights reading, experimenting, repeatedly failing, and eventually, learning…

Screen shot of ElasticDog v1.0

Once the initial design had been completed, I was pretty happy with the results, but didn’t know where to go from there. I had successfully created a functional/accessible site using XHTML and CSS; but they say that “content is king,” and I felt that at the time, I had nothing significant to write about.

And so, I kept researching as much as I could on web design, intermittently writing on what came to mind, and fooling around with different ideas that I ran across. In time, I began to develop my own thoughts on the subjects that I was reading about, rather than just taking what others said at face value. It was quickly becoming apparent to me that ElasticDog needed some major improvements.

Read More »