Visual Form Builder

Those of you familiar with the UA WordPress Theme have probably seen the contact form shortcode. It’s a basic contact form with a couple of customizations.  For most people looking to add a contact form to a web page, the shortcode does the job.  However, when you want a custom form things can get more complicated.  I have recently built a new plugin that I hope will make things a bit simpler.

Visual Form Builder is a free WordPress plugin that lets you dynamically build forms using a simple interface. Every form includes jQuery validation and a basic logic verification system as well as entry tracking.

A simple script

This plugin started out not as a plugin, but as a relatively simple PHP script that programmatically output the appropriate form code based on what fields and requirements I needed.  This first attempt wasn’t a failure by any means, but it did use some convoluted methods to construct the form.  If I had stopped here, I could have used the tool for a while and been happy with it because it was significantly faster than manually building a form.

The problem with this script was that it was something that really only I would be able to use and my goal was to create something that my co-workers at Web Communications and perhaps others within the UA web community could use.

With that in mind, I decided to turn the script into a form builder plugin for WordPress.

Building a form builder

Having released several other plugins in the last year, getting this one started was fairly straightforward.  Before I began building, I mapped out the requirements I hoped to meet:

  1. Use WordPress HTML/CSS for the admin panel to reduce design maintenance and present familiarity to the user.
  2. Make it easy to add form fields.
  3. Include support for fieldsets.
  4. Order form fields using a drag-and-drop interface.
  5. Use jQuery Form Validation to validate clientside.
  6. Don’t use a CAPTCHA system for anit-SPAM verification.
  7. Log all form submissions in the database.
  8. Export entries to a CSV.

With these features in mind, I began coding.  Not all of these features made it into the first version, but they are there now.

Certainly there are some other form builder plugins available for WordPress, including some commercial tools that offer a wide range of features.  The idea behind Visual Form Builder was to provide a quality, free alternative to the UA web community (or anyone else who finds it useful).

How do I use Visual Form Builder?

I’ve tried to make it as easy as possible to add and customize a form and have even added some help text to the contextual help tab at the top of the plugin page.  Here’s a quick primer on creating your first form.

  1. After downloading, installing, and activating the plugin, go to Settings→Visual Form Builder.
  2. Click on the + tab, give your form a name and click Create Form.
  3. Click the form fields from the box on the left called Form Items to add it to your form.
  4. Edit the information for each form field by clicking on the down arrow.
  5. Drag and drop the elements to put them in order.
  6. Customize the Email Details and Confirmation
  7. Click Save Form to save your changes.
  8. Copy the shortcode from the box on the left called Form Output
  9. Paste into any Post or Page and save your changes

If you have other questions, you can check the FAQ or leave me a comment.

Download it now and let me know if you have any suggestions, bug reports, or feedback.

Programming 101: How to Create Groupings

If you are new to programming, there may be certain solutions that escape you completely, depending on the problem you are trying to solve.  Sometimes it’s as simple as not knowing of a function or syntax.  Other times, it’s a little more complex because it involves logic.

What is Programming Logic?

Before we dive into code, I want to briefly explain what I mean when I say logicProgramming is essentially using code to creatively solve a problem.  Throughout your code could be a logical set of instructions that determines when to execute certain pieces. This is conditional logic.

Many times, the logic to solve a problem is pretty simple:

<?php 
if ( x == 2 ){
    echo 'This is the second record';  
}
?>

Using this kind of conditional logic is essential when you are learning how to program and, over time, will allow you to perform more complex statements.

What is a Grouping?

A grouping is where you sort a set of data into logical sections.  A great example of this is when you see an events calendar that is sorted by date.  There is a single heading for the date and each record that matches that date is listed underneath.

December 10, 2011

  • 12/10/2011 10:00 am – Mary’s Recital
  • 12/10/2011 12:00 pm – Bob’s Cookout

December 11, 2011

  • 12/11/2011 2:00 pm – Computer Science Meetup
  • 12/11/2011 5:00 pm – Art Festival

This sort of breakdown continues on until you get to the end of your data.

How do I make a Grouping automatically?

The above list is easy to create manually, but what do you do when you have hundreds or even thousands of events in a database?  Of course, that’s where programming is going to help us.

Here’s our pseudo code:

  • Query our events database – get all records for the current week
  • Loop through each record and print our information out to the screen
  • If this event’s date is not the same as the previous event’s date, print out our new date heading and continue

Here’s our actual code:

<!--?php<br /-->/* Setup our query - assuming we've already connected to our database */
$query = 'SELECT Title, StartDate, StartTime
FROM events
WHERE WEEK(StartDate) = "12-11-2011"
ORDER BY StartDate ASC, StartTime ASC';

$result = mysql_query( $query );

echo '
<ul>';

/* Loop through our events data */
while ( $row = mysql_fetch_array( $result ) ) {

    /* Assign each row to a variable */
    $title = $row['Title'];
    $date = $row['StartDate'];
    $time = $row['StartTime'];

    /* Handles the date grouping */
    if ( $last != $date ) {
        echo '
	<li class="date_heading">' . date( 'D M d, Y', strtotime( $date ) ) . '</li>
';

        $last = $date;
    }

    /* Output the event name and time below */
    echo '
	<li>' . $title . '-' . $time . '</li>
';
}

echo ';
?>

As you can see, with very little code, we can group our data. What’s even better is that the method can apply to any kind of grouping you need, not just dates! For example, you could have a directory of people and want to group alphabetically by last name (if ( $last != $last_name )). Or, you could have a blog archive page with categories grouped by name and the posts underneath (if ( $last != $category )). There are tons of possibilities.

If you plan to work with a lot of data that needs to be grouped into common headers, save this little snippet of code because it could come in handy.

JavaScript Libraries – jQuery (CCW Part 4)

To start off with, I wanted to title this ‘animations’, but JavaScript libraries such as jQuery can do so much more than just animation. I also did not want to get into teaching Flash.

Why not Flash?

Flash has been a big debate in the web community since its inception. Why? Because Flash is a self contained program running within a browser’s window. This sometimes causes browser crashes when something goes wrong and the browser has no way to compensate. More modern browsers have introduced isolated tabs to deal with this so that when Flash crashes, only the tab is affected.

Another strike against Flash, but which is not the product’s fault, is lack of support on Apple products. Mr. Jobs does not like Flash and therefore does not have support for it on his mobile OS. Thus, your iPad, iPhone, iPod, etc… does not show any Flash media.

So, what is Flash used for then? Flash is mainly used for streaming video, however there are people who use it to build dynamic websites. The film industry is a big user of Flash websites where they can create rich animated content. However, most websites don’t need this because people want quick information, not loading animation, when they visit a site.

So what do you use?

JavaScript.

JavaScript, once the evil monster with a thousand difficult tentacles of coding, has now been compacted into libraries which make code quicker and easier to use. Two script libraries stand out above the others: MooTools and jQuery, with jQuery being the #1 in popularity.

Since jQuery is so popular, and thus has a lot of uses, that is what I’ll be focusing on in this lesson.

Basic jQuery

I’m not going to get too into it since it can go on forever, but I will tell you about the areas and what they do by using a handy dandy image rotator example. What the given example does is that it takes a thumbnail’s link and information and transfers it to a different key set of areas when selected- thereby changing the main image and its description.

A few notes: Properly nesting and closing code is VERY important in jQuery. A misplaced ‘;’ will cause your entire code to fail.  For longer scripts finding a mistake is very hard, so be sure to keep notes (by commenting next to the code) on what you have changed.

Commenting in jQuery is easily accomplished. A comment looks like this:

//This is a comment in jQuery

Most code will be well documented with the above style of comments, but it is helpful to keep your own comments around to know what you’ve worked on.

Let’s dissect some code

It’s been my experience that when dealing with more complex codes jumping in and dissecting what the code is and what it does helps immensely with the learning process. Therefore, I’m going to throw a block of code down and then explain every single little piece of it and why it’s there and what it does.

$(document).ready(function() {	

	$(".main_image_wordbox").show(); 
	$(".main_image_info").animate({ opacity: 0.85 }, 1 ); 

	$(".navi_1 ul li").click(function(){ 
		
		var imgAlt = $(this).find('img').attr("alt"); 
		var imgTitle = $(this).find('a').attr("href"); 
		var imgDesc = $(this).find('.image_info').html(); 	
				
		if ($(this).is(".active")) {  
			return false; 
		} else {
			
			$(".main_image_1 .main_image_info").animate({ opacity: 0 }, 350 , function() {
				$(".main_image_1 .main_image_info").html(imgDesc).animate({ opacity: 0.85 }, 350 );
				$(".main_image_1 img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		return false;
	});
});

First off:            $(document).ready(function() {     });

This says that when the document (page) is ready (fully loaded), perform the function (actions) within the {}.  This, or a reasonable variant of it, will be on every jQuery script either in the actual plugin or within the page script.

Next, we specify some elements and what we’re going to do with them.

$(".main_image_wordbox").show();

$(".main_image_info").animate({ opacity: 0.85 }, 1 );

The $ specifies a new element in jQuery. The main_image_wordbox that I’m referencing from my CSS is now a primary element that will be acted upon.

The .show() is a jQuery action which tells the script to show the wordbox by default.  The ‘;’ closes the statement.

Next comes the information that is displayed within the wordbox. When the info changes, I want to animate it. Thus, I apply the .animate() action to the main_image_info CSS reference. Within the animate action, I set what I want to change/animate. In this case I want to change the property called ‘opacity’ to .85 so I place the properties within {} and specify the speed at which the animation will take place outside of the {} as ‘1’ so that it’s instantaneous/very fast.

Now we come to our main action:

$(".navi_1 ul li").click(function(){         });

When a list item is clicked within an unordered list in the CSS .navi_1 box activate the function within the {}.

var imgAlt = $(this).find('img').attr("alt");

var imgTitle = $(this).find('a').attr("href");

var imgDesc = $(this).find('.image_info').html();

‘var’ designates a variable which can be used over and over throughout the script. Thus, ‘imgAlt’ used further down in the script will naturally refer up to the ‘var’ and say “Oh, ‘imgAlt’ means to do this.”.

$(this) refers to the code above it- in other words   $(".navi_1 ul li").click

Thus, the first ‘var’ says when the li is clicked find the image within the li and get it’s attribute of alt.

So what it’s doing is this:   <li><img src=”image_thumnail.jpg” alt=”A Blue Building” /></li>

IE:  The first ‘var’ translates into- The variable ‘imgAlt’ is equal to ‘when the li is clicked find the attribute of “alt” within the image tag’.

The other 2 variables operate under the same principles.

Now comes your ‘if/else’ statement.

if ($(this).is(".active")) {

return false;

}

If your li is already clicked and therefore has the class of ‘active’ then do nothing. IE: Is animation needed? No? then “return false” – do nothing. ‘else’, if it isn’t already active then do the action within the else tags. Afterwards stop by ‘return(ing) false’ as the action taken is now active.

else {           } return false;

Going within the ‘else’ for the heart of your animation

$(".main_image_1 .main_image_info").animate({ opacity: 0 }, 350 , function(){

        $(".main_image_1 .main_image_info").html(imgDesc).animate({ opacity: 0.85   }, 350 );

	$(".main_image_1 img").attr({ src: imgTitle , alt: imgAlt});

});

The top tells me that when I animate the css elements I want to, by default, animate the opacity to 0 at a speed of 350. I further specify it by saying that within the animation of the objects the function(){} further expounds on what I specifically want done during the animation.

The animation function says that the animation consists of:

1. Replacing the .main_image_info’s html with the variable ‘imgDesc’ information and when doing so to animate the opacity to .85 at a speed of 350.

2. Taking the .main_image_1’s img tag and replacing the attributes of src and alt with the variables ‘imgTitle’ and ‘imgAlt’ information.

Putting it all together

So here’s how the script works:

The page loads and image rotator comes up and the text box appears. Animation instantly changes the text box to have a slightly lower opacity so you can moderately see the image behind it. It stops. Nothing happens until you click a list item (ie: thumbnail) which then takes the link location and alt on the thumbnail and shoves that information into the main image while taking the html out of the CSS class ‘image_info’ and placing that into the text box which at the start of the animation had faded to zero, but now fades back to the original .85 opacity. Animation ends. New image and text are displayed in the rotator.

Tada! You’ve just learned about a jQuery image rotator.

So what about all the other stuff?

Yes, jQuery does a lot more than this, but most of it is easily customizable and come in the form of various plugins. The above example was to give you an insight into how jQuery basically operates/works.

For more information on jQuery and a list of its plugins, go to:      http://docs.jquery.com/Main_Page

Learn from the pros at UA’s ‘Web for Dummies’ class

There’s still time to register for our upcoming “Web For Dummies” class, scheduled for Tuesday, February 22nd at 8:30 a.m.  Learn from a group of UA’s own web experts about how to construct, maintain, and promote a website. The class will cover how to set up your site with OIT, planning your site, customizing UA’s HTML Templates, working with UA’s WordPress Theme, and using social media to broadcast information. During and after the lecture Q&A sessions will be held where you will have the opportunity to ask a good selection of UA’s web community questions.

The class will be held in the Capstone College of Nursing Building, room 1012 on February 22nd from 8:30am to 1:00pm with individual sessions starting at different times during that period. Registration is required for the class because of limited seating. For more information on times, sessions, and registration, please refer to the PSA website at http://psa.ua.edu/?page_id=531.

WordPress & PHP (CCW Part 3)

Working with UA’s WordPress Theme

UA’s WordPress theme makes use of an options panel which is located inside the WordPress dashboard. This allows for a more hands off the code type of customization. There are play by play instructions on how to use the theme located on UA’s Web Guide, http://webguide.ua.edu/wordpress.html, so we won’t be covering that.

What we will be discussing is what a WordPress Theme is composed of and how the system works to display information.

WordPress file organization/main editable pages

When you’re looking through WordPress files, you might want to know which are relatively safe to bring up and edit code wise.

WordPress takes a theme and chops it up so that it can mix and match- separating elements in a way that allows all pages to make use of common parts. (Think of it like a Mr. Potato Head.)

For example: Your header should be the same on every page- regardless of the content. Thus, WordPress takes the header and creates a file called header.php which should contain all your header elements. When you call up a page in your browser, the PHP in the content part of the page calls ‘get_header’ and so the header appears at the top of your page.

Main structural elements:

index.php                your main ‘blog’ page and default home

statichome.php     a homepage that does not have blog style content rotating on it (optional- you make it)

single.php                the base page for all your blog pages or ‘posts’

page.php
                  the base page for all your ‘pages’

sidebar.php            where your sidebar is located

header.php             where your primary horizontal navigation is located

footer.php               where your footer is located

The footer, header, and sidebar will generally have your links and navigational elements. The index, statichome, single, and page will have your content. 

Content structure/hierarchy is shown below.

Structure of a completely built WordPress page is shown below.

The header will contain all your CSS, just like normal as well as your horizontal navigation.

The content page will have php linking it to the header, sidebar, and footer. The content page shown here happens to be the blog index page.

The sidebar contains your secondary links and can be placed within your content page where ever you want it to appear.

The footer will contain all your animation scripts such as JavaScript and its libraries.

PHP in WordPress

This is not a programming course, so we’re not going to dive into the proverbial PHP pool. However, that being said, I do want to give you a few helpful scripts and explain what they do. Why? Well, if you choose to have a ‘statichome.php’ that will do some things in connection with WordPress’ database- well, it just won’t fly the HTML way.

This is where PHP template tags come in. For a complete list, please refer to the WordPress Codex: http://codex.wordpress.org/Template_Tags

Template tags are used within your blog’s .php template pages to display information dynamically or otherwise customize your site. What most tags will do is pull information out of the database. Other tags arrange structure- such as the “get_header” or “get_footer” tags that attach those elements to a page.php or single.php.

Referencing

WordPress has its own database for managing content and information. In order to access the information, a PHP script is needed to make the browser load the info from the database.

In order to reference things housed in the database without knowing the entire location of the object, we use:<?php bloginfo(); ?>

This PHP gets information from the WordPress database.

A practical example and most likely the only time you’ll really use this is for images:

<img src="<?php bloginfo("template_url"); ?>/images/name.jpg" />

Elements you might like to customize display on

Some elements you might want to customize display on would be the date and time.

<?php the_date (); ?>                             <?php the_time(); ?>

You might want something short like “Thu, 21 Dec 2034” or a little longer as in “Thursday 21, December 2034”. So where are the above two examples used? They can be used anywhere- but mostly you’ll see them as ‘date posted’ in blog posts or news releases.

How to use:

<?php the_date (‘m-d-Y‘); ?>        displays:    month-day-year   ex:  08-03-2034

<?php the_date (‘M  d, Y‘); ?>     displays:    month day, year   ex:  Aug 03, 2034

<?php the_date (‘F j, Y‘); ?>       displays:    month day, year   ex:  August  3, 2034

<?php the_time(‘D, g:i a’);  ?>    displays:    day, hour:minutes am/pm  ex: Tue, 9:45 am

<?php the_time(‘l, G:i’);  ?>        displays:    day, hour:minutes  ex: Tuesday, 17:45

For more information on formatting date and time, see: http://codex.wordpress.org/Formatting_Date_and_Time

Within WordPress’ Control Panel

Most organizational customization can be easily achieved within the control panel. One of the major adjustments you’ll make in the control panel is deciding your site’s style.

Site Styles

There are 3 kinds of website homepages available: Blog Style, Static Homepage, or a combination of the two.

Blog Style
By default, WordPress will display the homepage of your website as a blog. For many themes the default will be to use a blog-style homepage.

Static Homepage
If you would like to use a static homepage to give your website a traditional website feel, there are several steps you must take:

  1. Login to your WordPress account and create a new page called ‘statichome’. Only fill in the title box. Leave the rest of the page blank.
  2. To the right is a section called ‘Attributes’. Under ‘Template’ select ‘Static Home Page’ and publish the page.
  3. Make a new Page called ‘blog’ and publish. (Once again, only fill in the title box, and this time do not make any changes in the ‘Attributes’ section.)
  4. Under ‘Settings’ on the main left toolbar, select ‘Reading’.
  5. Select ‘static page’ and set the front page as ‘statichome’ and the posts page as ‘blog’. Then save the changes.

Now when you visit the actual site, your static homepage will show up as the index instead of the blog page.

Static Homepage with Blog Page
If you decide to use a static homepage, but you still want to have a blog on your site elsewhere, all you need to do is include an absolute link to your blog within your main or side navigation. You can find this link by going to the ‘blog’ page that you created above.

HTML & CSS (CCW Part 2)

After you’ve figured out navigation, layout, and sent out requests for content, it’s time to start building your site. This lesson deals with basic HTML and CSS along with best practices using for both.

There are many web editors out there, but for this lesson I’ll be using Dreamweaver’s basic starter page for my example.

Starting on the build

So, let’s have a look at what a blank page looks like in code. A basic Dreamweaver HTML page is shown below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document Title</title>
</head>
<body>
</body>
</html>  

There are six parts here that make up a solid base for your page. Your Doctype, html  tags, head tags, meta data, the title tags, and last the body tags. All are part of the HTML code.

HTML (HyperText Markup Language)

Your HTML is the skeleton for your CSS. It supports the body of your webpage while CSS provides the muscles and skin. Therefore, if your HTML is incorrect, it doesn’t matter if the CSS is perfect, your website will fail.

First off, let’s talk about HTML and XHTML (Extensible HyperText Markup Language). HTML is mainly comprised of tags like the example above. XHTML is not very different from HTML- except that it’s stricter which allows browsers to process the code faster and eliminate errors caused by incorrect markup.

For example, <img src=”example.jpg”> would not display in XHTML because the ‘img’ tag is not closed. To display correctly, it would need to look like this:<img src=”example.jpg” />

Yes, the ‘/’ needs to be at the end of every tag to close it in XHTML.
HTML is not so picky and will take either <img src=”example.jpg”> or <img src=”example.jpg” />.

Generally, it is good to use HTML for your doctype, but practice XHTML within the HTML. Why? Because it’s better for the browser.

XHTML within HTML

By following all the XHTML rules you help the browser load pages faster and it’s less confusing to search through. That’s where XHTML is a plus- however, you may not know all the rules of XHTML, or you might miss a rule by accident, rendering your whole page useless until you find the problem. HTML doesn’t care about little mistakes, so by using XHTML style in and HTML page, you cover accidental code flubs so that your page will still work when you open it.

Some major differences in XHTML and HTML

HTML

<br>      <hr>       <img src="example.gif">
<P>Something</P>

XHTML

<br />      <hr />      <img src="example.gif" />
<p>Something</p>

For more on XHTML rules:           http://www.w3schools.com/xhtml/xhtml_html.asp

HTML Basics

NOTE: I’ll be writing in XHTML, but I use it within an HTML framework. Keep this in mind.

What is a “doctype” and why is it on my page?

First off, the doctype declaration should appear before any other markup on your page. Why? Because it is an instruction to the web browser about what version of the markup language (eg: HTML, XHTML and their variants) the page is written in.

For more on this see:            http://www.w3schools.com/tags/tag_DOCTYPE.asp

Placement

The placement of code in the HTML specifies what elements are within elements and their hierarchy to other elements. For example, let’s say I wanted a box within a header. I would have:

<div id=”header”><div class=”box”>Box Content</div></div>

The ‘div’ tag calls the CSS to place the header on the page and insert the box into the header. It is very important to close your divs as it tells the CSS styling to stop past the ‘</div>’ point. It is also important to nest your tags to avoid conflicting style properties or code errors. To style the elements for each div tag, you must go into the CSS and not the HTML. Remember that most HTML is strictly for organizing.

<head>…</head>

Your ‘head’ tags should contain all information a browser needs to render the content in the ‘body’ tags as well as information pertinent to search engines and browser needs for your page.

Tags used in the ‘head’ are:

<title> ... </title>      displays title of page for the browser to put on the tab or on the window’s title bar
<meta />  gives data for search engines to organize your page by/tells what your page is about
<base />   specifies a default address or a default target for all links on a page
<link />  gets a resource reference such as a CSS style sheet

An example for calling a style sheet is below.

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

So, what’s going on here?

Well, ‘rel’ says that the relationship between the current document and the linked document is that it’s a style sheet, ‘href’ calls the actual style sheet from its location,  ‘type’ tells us that the style sheet  is formatted in text/css, and ‘media’ tells us that it’s for a computer screen.

If you wanted to make this style sheet for a phone, you would change ‘media=”screen”’ to ‘media=”mobile”’. ‘media’ allows you to have multiple style sheets on a page that target different devices. (ex: style sheets for mobile, print, and screen)

<body>…</body>

Your ‘body’ tags contain the page elements that will show up in the browser window. Organization of these elements is key. Keep your tags correctly nested. I can not stress this enough. Keeping tags well organized in your code will help in a lot of ways.

Some commonly used tags in the ‘body’ are:

<h1> ... </h1>  creates a heading with h1-h6, h1 being the largest and h6 being the smallest
<p> ... </p>    organizes content into paragraphs
<a></a>  designates a link
<img /> places an image within the page
<br /> puts a break in-between text
<hr /> creates a horizontal rule- ie, a line- between elements
<strong> ... </strong>   strong emphasized text (bolds text)
<em> ... </em>  emphasized text (italicizes text)
<ol><li> ... </li></ol>  ‘ol’ is an ordered list, ‘ul’ is an unordered list, ‘li’ in both ‘ul’ and ‘ol’ is a list item
<div> ... </div>  tag defines a division or a section in an HTML document- mostly used to call style elements from the CSS
<form> ... </form>  used to place a form element within the page

Some natural hookups:

There are some tags that naturally have certain things following them.
For example, <a href=”...”> ... </a>.

‘a’ says that it’s a link and ‘href’ tells the link where to go. <img src=”...” /> ‘img’ says that the element is an image and ‘src’ tells the location of the image you want displayed.

Putting together CSS and HTML using ‘div’

The ‘div’ tag when used with CSS will either have ‘id’ or ‘class’ attached to it.

ex: <div id=”...”> ... </div> or <div class=”...”> ... </div>

A ‘div’ can have multiple classes attached, but only one id. Also, a certain id can only be used once on a page where as a certain class can be used multiple times.

ex: <div id=”container” class=”numberone” class=”numbertwo”> ... </div>

BEST PRACTICES

  • Put CSS in the header just above the </head> tag. (In order to have all styles ready for the body when it loads.)
  • Put links to scripts as well as scripts themselves (ex: jQuery, mootools, javascript) at the bottom of the page- just above the </body> tag. (This encourages faster page loading.)
  • Keep things well organized and, when necessary, document where your div tags end like so: </div> <!-- example div ends here -->
  • Nest your tags.

CSS (Cascading Style Sheets)

Getting the look

The main styles of the site, look and layout, are controlled mainly through CSS. If you need to edit the presentation of an element, div, or id use CSS. CSS and HTML together make a website fast loading and easily customizable. Using a CSS style sheet, you can change an element of your site across all the pages that have that element simply by editing your CSS. This cuts down on mistakes and makes your time spent on code more efficient.

CSS Example

Some examples of CSS.

h1 {
font-size: 2.6em;
padding:5px 0 20px 0;
}
#content {
padding-top:15px;
font-family:Verdana, sans-serif;
}
.sec-nav {
padding:0;
margin:0 0 30px 0;
}
li:visited {
color: #00CC00;
text-decoration: none;
font-weight: bold;
}  

Writing style

Before we get into the guts of this operation, I’m going to tell you about how people write the optional parts of code.

There are 3 types of naming conventions:

  • camel case
  • dash
  • underscore

Let’s say I have something in my CSS I want to call “Slider Thumbnails”.   Well, spaces are defined as starting something new, so I can’t use the above. Solution- one of the 3 naming conventions.

Camel Case:      sliderThumbnails

Dash:                  slider-thumbnails

Underscore:      slider_thumbnails

Which do I use? I use underscore because it seems easier to read for me, but this is all subjective. You pick the style that works best for you. What is important is that there are no spaces within the name.

About CSS

CSS can be used in three different ways: inline, internal, and external.

Inline is when you use ‘style’ attached to an element to build CSS for a single element within the HTML.

ex:   <p style=”color:red;”>…</p>

Internal is when you place your CSS styles in the ‘head’ tags.

ex: <head>
<style type="text/css"> p  {color:red;} </style>
</head>

External is when you have a separate style sheet and link to it from the ‘head’.

ex: <link rel="stylesheet" href="style.css" type="text/css" media="screen" />

The external style sheet will have formatting like this inside it: p  {color:red;}

What is a CSS format?

CSS creates a selector for HTML to use when you group elements you want styled on your page. The selector then has notes on what properties you want added and what you want the properties to be.

ex:   selector { property:value; }

There are 2 ways of organizing CSS: single line and multiple line – both are correct so it’s a matter of preference which one you use.

selector { property:value;  property:value; }

selector {
property:value;
property:value;
}

Your selector can be named anything you want. (With the exception of element selectors.)

Different types of selectors

There are different types of selectors: element, id, class, and pseudo.

Element selectors retain their proper html titles such as ‘body’, ‘p’, ‘h1’, ‘ul’, ‘ol’, ‘a’, ‘img’, etc… and do not use any identifying features. ex:  img

Id selectors use ‘#’ before a name and are unique.  ex:   #container

Class selectors use ‘.’ before a name and are not unique.   ex:   .thumbnail

A pseudo selector uses ‘:’ and must be attached to an element selector.    ex:    a:hover

As stated before in the html section, an ‘id’ is unique and the same id can’t be used numerous times on a page. Use ‘id’s for main containers and other large boxes on a page. A ‘class’ is not unique and can be used multiple times on a page or multiple times on an element.

For more on this see:            http://css-tricks.com/the-difference-between-id-and-class/

Property and value

A property in CSS tells what you want to style within the selector and the value tells how you want it styled. For instance, I would like a red boarder around my header.

ex:   #header  {border-color:red;}

“#header” would be my selector while “border-color” would be my property. “red” is the value I want displayed as the “border-color” on the “#header”.

There are many different types of properties. Some deal with position while others handle styles and spacing. For a full list of properties, see http://www.w3schools.com/css/css_reference.asp and scroll down to CSS Properties.

Decoding CSS

Let’s take apart this CSS.

#wordmark{
background:url(images/wordmark.png) top left no-repeat;
width:709px;
height:112px;
position:absolute;
top:0px;
left:10px;
text-indent:-9999px;
margin:0;
}

It’s an ‘id’ named wordmark.
It has a background image placed in the top left and the image is not repeated.
It’s 709×112 pixels, and its position is absolute on the page with the coordinates being top 0 and left 10. It has a text indent of -9999px, which means the text is hidden off the page, and the margin is 0 so other elements will come right up against it.

Most CSS properties are easy to figure out. Especially in things they control. Just use common sense and in most cases- what you think it does it what it does. Some tricky properties are ‘color’, which actually controls the color of your text, and ‘margin’ vs ‘padding’.

Margin determines the amount of space around your element.
Padding determines the amount of space within your element.

Bundle up

Sometimes you want to specify a lot of things that actually all relate to one property. Well, there is a way to do that.

background:#990000 url(images/footer-bg.png) top left repeat-x;
font:bold 1.7em/175% "Lucida Sans",Lucida Sans Unicode,Verdana,Helvetica,sans-serif;
border:1px #ccc dotted;
padding:4px 0 4px 4px;
margin:3px 0px 10px 15px;

This helps lighten your code and makes things run faster. It also makes things easier to find.

BEST PRACTICES

  • Separate your sections with descriptive headers. (ex: /* styles for slider */)
  • Use CSS to style all links and header elements so that they appear the same throughout the site.
  • Watch out for conflicting CSS. In order to remove conflicts, sub list the element when necessary. (ex: #containingDiv h1)

Organization and Introduction (Crash Course in Web Part 1)

Over the past year I’ve found myself doing more and more teaching on web development. Considering how much I’ve invested in it, I decided to post some of my updated lessons here on WebTide for others to look over.

The first lesson deals with organization and planning while further lessons will handle coding. As these lessons were originally intended to be handouts for a lecture, please feel free to post any questions on the material in the comments section. I can’t promise I’ll get to them all, but I’ll try.

Setting up structure for a website

Most people don’t know how essential good navigation is- but every website I’ve ever built has required at least an hour of debate over navigation.

Navigation is very important as it organizes the content flow on your site. While planning the navigation, make sure to stress the user’s point of view. Role-play if you must. Imagine you know nothing about how the company works and just want to find something- where would you most likely look for it? This should help you construct the primary navigation. Lesser links can be placed in a sub navigation that’s not as prominent or used as secondary navigation within pages.

People generally don’t like clicking more than 3 times to find what they want- but they also don’t wish to be stuck on the first page for hours searching for the link they need. To help solve this problem, use umbrella terms in your main navigation and let your secondary navigation fine-tune the section. In the best possible situations you’ll only need these two levels. Larger sites with more content may require further links, but place them within the page to avoid confusion or frustration.

Tip: When working out your navigation, don’t fixate on users who are only going to visit your site once. Plan for those who will be visiting your site frequently and make sure their content is easily accessible.

Create a navigational chart

In order to make sure everything is correct, mock up a navigational chart. In this way, clients will be able to see the site’s flow and easily edit mistakes. This heads off a lot of arguments before you start coding since some people need to see navigation before they understand it. Two recommended ways to create a navigational chart are in outline style or as a data tree. Both have inherent hierarchy when created and allow for easy secondary navigation insertion.

Create a content layout model

How information is displayed on a page is also important. Remember that your users will usually be looking for one specific bit of information and won’t want to read your entire site to get it. Make things easy to spot on a page by using well-defined headers and bolding/italicizing only very important elements.  Organize your page in a way that will allow the user immediate access to the information they want with a simple scan.

For each page, your content layout will naturally differ depending on the type of information. Understanding your audience, and what your audience wants, helps identify which elements are important, and where these elements should be placed. The one exception would be your home page, which should focus on emotional impact in addition to user needs. This impact is often accomplished by having a picture, illustration, or good typography showing what the organization is about.

When working on a home page layout, you may find that sketching out your ideas can be very helpful. They don’t have to look professional, they just act as a visual guide to help place your content. Use a grid and plan your layout with boxes and squiggles. This helps you figure things out before you start coding and saves time.

BEST PRACTICES

  • Have main umbrella navigation terms for your main menu and keep them short.
  • Keep important information within 3 clicks of the user.
  • Advocate for the users of the site.
  • Outgoing links should never be placed in your main navigation, though there are some exceptions.
  • Keep in mind that companies tend to know their customers and business. If they insist on something you think is bad practice, compromise or give in depending upon the situation.

Getting comfortable with content

When it comes to reading a site, people want content to be clear, concise, and legible. In order to facilitate this, shorter sentences are used and body copy fonts are mostly sans-serif. There’s a good reason you see Verdana and Arial on the majority of web pages. Every computer has them pre-installed and they’re easy to read at smaller sizes.

Request content before you start coding the site, but after you’ve got the navigation planned. It takes time for people to write and by letting them know what you want, before you need it, the process will go much smoother. However, there may be times when you’ll need body copy and none is available. This might crop up while you’re building a site and want to see how content will look in your layout. For this, most turn to the old printer’s resource of Lorem Ipsum.

Lorem Ipsum is dummy text and has been used by the printing and typesetting industry since the 1500s. When websites came along, the same principles were used in their creation and thus the text made the leap from paper to screen. Just make sure that Lorem Ipsum is erased when you get the actual content.

Trivia: Lorem Ipsum is Latin and comes from Cicero’s “de Finibus Bonorum et Malorum” which was written in 45 B.C.

Image content is another beast altogether. A few things I recommend are getting a professional photographer or going to a stock photo site. With professional images your site will look better and inspire more trust with users. Also make sure your image conveys the same message as your text. Think of a few adjectives that describe your organization. Do those adjectives apply to your pictures? If not- don’t use them.

BEST PRACTICES

  • Request content ahead of time.
  • Use bolding and italicizing sparsely for only important elements- the more bolding and italicizing you have, the less important and more confusing those elements become.
  • Make sure your content is edited for grammar and spelling.
  • Use professional images that convey your organization’s purpose throughout the site.

WORST PRACTICES

  • Don’t center your content- especially with paragraphs.  Centering rarely looks good and reading from a jagged edge is hard on your users.
  • Using too many fonts is confusing. Limit yourself to 2 different fonts (usually one serif and the other sans-serif) and use one font for headings and one for body copy.
  • Some fonts are downright inappropriate for their subject matter. Comic Sans gives a childish feeling and unless your site deals directly with children- don’t use it.
  • Stay away from site traffic counters or gif animations. They date your site like nothing else.



RSS for sites with no RSS (updated)

[Author's addendum: As of September 30, 2010, Google will discontinue this service. According to their blog post, Page2RSS can perform the same service as Google Reader's "track changes" and can even convert your already existing feeds.]

I’ve been a big Google Reader fan for years now, and I wanted to point out a feature that may not get as much recognition as others. Sometimes you want to add a feed for a site that just doesn’t have a feed. Surely there’s a better way to look for updates than bookmarking and (ir)regularly scheduled visits, right?

Turns out you can add a site to Google Reader even without a true RSS feed available. Google will watch that page for you and generate a Reader item when an update is found.

For example, I want to keep an eye on OIT Current News. I click into Reader and “Add a subscription” like I normally would, then add the normal URL of the OIT Current News page.

Google tells me, http://oit.ua.edu/news/current.html does not provide a feed. We can create a feed for you, notifying you when the content on the page updates. (Learn more.)”

So far it’s worked brilliantly; I’ve gotten Reader items for each of the last three OIT Current News updates. Just another way Google can help bring the web to you!

Introducing the new UA WordPress Theme

Exactly two months ago, we launched the first versions of our UA WordPress Themes. These themes provided web designers and developers with easy way to implement our web templates into a CMS.

However, in that time since launch, there have been great advances in functionality for WordPress, namely WordPress 3.0. In anticipation of this launch, Web Communications have been developing a newly unified and dynamic theme to take advantage of some of these features.

The first thing you will notice is that we have managed to reduce the number of themes or folders from 12 to 1. This is a huge step in improving the simplicity of using WordPress for a UA site and installing/choosing a theme.

What’s New

  • UA Theme Options panel
  • Dynamically generated navigation theme
  • Navigation menu creation directly within WordPress
  • Widget capable sidebars
  • Selectable content layout within WordPress

UA Theme Options panel

Probably one of the most noticeable differences with this theme is the addition of a UA Theme Options panel. Thanks to an open source framework for creating theme options WordPress users with admin rights will be able to control major design aspects of their theme without ever touching the code. Such theme options include:

  • Search box in header: select whether or not to include the search box in the header
  • Navigation type: controls the type of horizontal navigation you want (one level, two level, or none)
  • Content layout: controls the layout of your content and sidebar locationBy configuring these options, you will be able to create all the variations of our original UA Web Templates. Once you save these options, you will be able to instantly preview the live site and view the changes.

Menus

With WordPress 3.0, we were able to include the new Menus feature into our theme. You are now able to create and manage your primary, secondary, sidebar, and footer navigation all within the WordPress admin.

Widgets

The UA WordPress Theme now supports widgets in the sidebar. Each UA “linksbox” style is included to give you the greatest number of options to uniquely style your site.

I believe that this theme will allow the average user to easily make their site unique while still conforming to the UA look and feel. In some respects, we are taking the “design” out of the hands of the coder and into the hands of the user. Needless to say, I think this is a huge step forward. Detailed tutorials on many of the new features of the UA WordPress Theme will follow in the coming weeks.

For more detailed information on the UA WordPress Theme, please read our WordPress guide on WebGuide.

Download

Go here to download the new UA WordPress Theme.

As always, comments and feedback are welcome.

UA Mobile Web Templates

As mentioned in our announcement of UA Mobile Web, resources on how to get started designing and developing your own mobile site are now available on UA Web Guide.  Currently, this documentation provides themes for the iPhone and Blackberry devices.  As UA Mobile Web expands functionality to other devices, so too will Web Guide’s resources.

The documentation provides code and instructions for:

  1. Automatically detecting mobile devices and forward to a mobile theme
  2. Setting a PHP cookie which allows the user to get back to the full website
  3. Different themes for each targeted device

Click here to download the UA Mobile Web Templates

We believe providing these resources will speed up development time for others on-campus and push forward mobile accessibility at UA.  If you have any questions or comments, please let us know.