Captionated: Or Why 456 Berea Street is Bad For Your Health

Using JavaScript to add captions to all or some of your images. The JavaScript is unobstrusive so that you miss nothing other than the caption if the user's browser has JavaScript turned off.

Continue reading "Captionated: Or Why 456 Berea Street is Bad For Your Health"

Commercial Template: Six-Oh-Six

Commercial Template Six Oh Six Screenshot

Here it is! My first commercial template! :-) It costs $50.00. Until I can get PayPal working with my template, e-mail me if you want the template. :-)

One Penny Wordpress Theme

One Penny Wordpress Theme Preview

ThemePorter contacted me recently regarding porting my templates over to Wordpress. OnePenny is now available. :-)

Whew!

After a marathon coding session, I finally have the new design online. I'm rather pleased with the design at the moment, and, hopefully, I'll remain just as pleased with in the coming months. You might have noticed ( if you didn't, notice it now ) the urls. I managed to get rid of the index.php in an extremely hackish way, but then, I tend to be anal-retentive about these kind of things. Also, the urls don't include subdomains anymore. While it seemed like a good idea back when it started, it started grating on my nerves the last couple of days. Undoubtedly, this is going to cause broken links and what-not, but hopefully everything will be back to normal in a couple of weeks.

There are a couple of things left to do still — namely, the contact form and the search results page...

One Penny

One Penny Template Screenshot

Feel free to do whatever you want with it as long as it doesn't involve making money off of it. As always, a mention and a link though not required is appreciated very much.

A Wordpress theme based on this template is forthcoming. So stay tuned.

[ View the template ]

[ Download the template files ]

Listing Top Categories in Wordpress

For my footer, I wanted to list the top ten categories (as calculated by the number of posts in each category). Bizarrely enough, there isn't an easy built-in way to do this with Wordpress. What's more surprising is that I couldn't find a plugin that provided this functionality, either. Maybe I'm the only person with this requirement. At any rate, this is how I solved the issue:

  1. <?php
  2.  
  3. $top_cats = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY category_count DESC LIMIT 10");
  4.  
  5. foreach($top_cats as $cat)
  6. {
  7. $cat_link = '<a href="index.php"' . $cat->category_nicename . '">';
  8. $cat_li = "<li>$cat_link $cat->cat_name</a></li> ";
  9. echo($cat_li);
  10. }
  11.  
  12. ?>

Tips to Make Tabular Data More Readable

An unstyled table is like nails on blackboard, more so than any other part of the web page. It’s especially important to style the table in a pleasant manner when you have lots of data to present. Imagine if your table contains a couple of hundred elements. Pretty soon all the rows start to blur together. It’s extremely frustrating to the user, and frustrated users are bad for business.###Zebra Tables

One common method used to increase table-readability-and-usability is by highlighting the alternate rows with a different color:

<

p class="img">Zebra Tables Example

I use this technique quite a lot, and one of the frustrating things is that when you hard-code which rows are alternate (by adding the class = “alt” directive to the row itself), it becomes a nightmare if you have to change the order of the rows for some reason. This is something that happens a lot to me while the application is still in development. One easy way to “fix” this is by using javascript to add the “alt” class to the alternate rows on the fly:

function highlightAlt()
{
    var theTable = document.getElementById("theTableId");

    var theTRs = theTable.getElementsByTagName("tr");

    for(var i = 0; i &lt; theTRs.length; i += 2)
    {
        var currTR = theTRs<i>;

        //The space is here to set it off from any other
        //classes the tr might belong to
        currTR.className += " alt";
    }

}

Highlighting Row When User Clicks On It

Suppose you have a table that has a hundred elements. The user selects whatever rows he wants (via checkboxes) and then clicks a button at the bottom to perform an action. While the checked checkboxes in the row might provide clue to what rows she selected, it pays to make it more obvious by highlighting it. Javascript to rescue again:

function highlightOnClick()
{
    var theTable = document.getElementById("theTableId");

    var theTRs = theTable.getElementsByTagName("tr");

    for(var i = 0; i &lt; theTRs.length; i++)
    {
        var currTR = theTRs<i>;

        currTR.onclick = function()
        {
            if(this.active == true)
            {
                var index = this.className.indexOf(" clicked");
                this.className = this.className.substr(0, index);
                this.active = false;
            }

            else
            {
                this.className += " clicked";
                this.active = true;
            }
        }
    }
}

I’m sure there’s a much easier way to replace “clicked” with an empty string. But as I’m a newbie javascript coder, I couldn’t make anything else to work. I wasted a lot of time with the Replace() function but that refused to work.

Allow User to Select a Row By Clicking Anywhere on the Row

The checkbox is a small tiny thing that’s stuck somewhere at the very left or right of the row. It makes the users’ life a lot simpler and happier if they can select the checkbox by clicking anywhere on the row, and I’m all for making users happier, especially as I need to add only 4 extra lines to the code in Listing 2 to make it everything work.

The updated code, then:

function highlightOnClick()
{
    var theTable = document.getElementById("theTableId");

    var theTRs = theTable.getElementsByTagName("tr");

    for(var i = 0; i &lt; theTRs.length; i++)
    {
        var currTR = theTRs<i>;

        currTR.onclick = function()
        {
            if(this.active == true)
            {
                var index = this.className.indexOf(" clicked");
                this.className = this.className.substr(0, index);
                this.active = false;

                var chk = this.getElementsByTagName
                            ("input")[0];
                chk.checked = false;

            }

            else
            {
                this.className += " clicked";
                this.active = true;

                var chk = this.getElementsByTagName
                            ("input")[0];
                chk.checked = true;
            }
        }
    }
}

It’s a good idea to keep in mind accessibility rules as you create your tables. I’m not going to mention styling the headers, because that’s something most people do by themselves. For alternate row color, it’s a good idea to use faded colors so that it doesn’t get in the user’s way. #dddddd and eeeeee are my favorite. ;-)

2 of 2 pages  <  1 2

On the Side