Get found on the web

Quality Web Design for Small
to Medium Businesses in New Hampshire

SearchCap: The Day In Search, January 12, 2012

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about html5

Below is what happened in search today, as reported on Search Engine Land and from other places across the web. From Search Engine Land: To Understand Google Favoritism, Think “If Google+ Were YouTube” Google’s favoritism of Google+ in its new Search Plus results is just the…



Please visit Search Engine Land for the full article.




Search Engine Land: News & Info About SEO, PPC, SEM, Search Engines & Search Marketing


Google “Search Plus” Impact on Local: Limited So Far

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about html5

Amid all the controversy that has erupted over Google’s new search personalization (Search Plus Your World), I’ve been doing local searches to see what if any impact it’s having on that arena. So far, in my unscientific query survey, the impact seems to be minor. Below are some…



Please visit Search Engine Land for the full article.




Search Engine Land: News & Info About SEO, PPC, SEM, Search Engines & Search Marketing


Password strength verification with jQuery

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about photoshop

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/jnthumbnail.jpg”> class=”alignleft size-full wp-image-28549″ title=”jnthumbnail” src=”http://netdna.webdesignerdepot.com/uploads/2011/12/jnthumbnail.jpg” alt=”" width=”200″ height=”160″ />Many sites that require login credentials enforce a security setting often referred to as password complexity requirements. These requirements ensure that user passwords are sufficiently strong and cannot be easily broken.

What constitutes a strong password? Well, that depends on who you ask. However, traditional factors that contribute to a password’s strength include it’s length, complexity, and unpredictability. To ensure password strength, many sites require user passwords to be alphanumeric in addition to being a certain length.

In this tutorial, we’ll construct a form that gives the user live feedback as to whether their password has sufficiently met the complexity requirements we will establish. id=”more-28522″>

Before we begin, let’s get take a sneak peak at what our final product will look like (click for a demo):

href=”http://dl.dropbox.com/u/636000/password_verification/index.html”> class=”alignnone size-full wp-image-28531″ title=”Final product” src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step141.jpg” alt=”Final product screenshot” width=”615″ height=”475″ />

Please note: The purpose of this tutorial is to show how a simple script can be written using javascript and jQuery to enforce password complexity requirements. You’ll be able to add additional requirements to the script if needed; however, note that form validation (server- and client-side), form submission, and other topics are not covered in this example.

class=”spacer_” />

Step 1: Starter HTML

First we want to get our basic HTML starter code. We’ll use the following:

<!DOCTYPE html>
<html>
<head>
	<title>Password Verification</title>
</head>
<body>
	<div id="container">
		<-- Form HTML Here -->
	</div>
</body>
</html>

class=”spacer_” />

Step 2: Form HTML

Now let’s add the markup that will be used for our form. We will wrap our form elements in list items for better structure and organization.

<h1>Password Verification</h1>
<form>
	<ul>
		<li>
			<label for="username">Username:</label>
			<span><input id="username" name="username" type="text" /></span>
		</li>
		<li>
			<label for="pswd">Password:</label>
			<span><input id="pswd" type="password" name="pswd" /></span>
		</li>
		<li>
			<button type="submit">Register</button>
		</li>
	</ul>
</form>

Here’s an explanation of the code we used:

  • span elements – these will be used for visual styling of our input elements (as you’ll see later on in the CSS)
  • type="password" – this is an HTML5 attribute for form elements. In supported browsers, the characters in this field will be replaced by black dots thus hiding the actual password on-screen.

Here’s what we’ve got so far:

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_2.png”> class=”alignnone size-full wp-image-28532″ title=”Step 2″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_2.png” alt=”Step 2 Screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 3: Password information box HTML

Now let’s add the HTML that will inform the user which complexity requirements are being met. This box will be hidden by default and only appear when the “password” field is in focus.

<div id="pswd_info">
	<h4>Password must meet the following requirements:</h4>
	<ul>
		<li id="letter" class="invalid">At least <strong>one letter</strong></li>
		<li id="capital" class="invalid">At least <strong>one capital letter</strong></li>
		<li id="number" class="invalid">At least <strong>one number</strong></li>
		<li id="length" class="invalid">Be at least <strong>8 characters</strong></li>
	</ul>
</div>

Each list item is given a specific ID attribute. These IDs will be used to target each complexity requirement and show the user if the requirement has been met or not. Also, each element will be styled as “valid” if the user’s password has met the requirement or invalid if they haven’t met it (if the input field is blank, none of the requirements have been met; hence the default class of “invalid”).

Here’s what we have so far:

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_3.png”> class=”alignnone size-full wp-image-28533″ title=”Step 3″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_3.png” alt=”Step 3 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 4: Create background style

We are going to give our page elements some basic styling. Here’s an overview of what we’ll do in our CSS:

  • Add a background color – I used #EDF1F4
  • Add a background image with texture (created in Photoshop)
  • Setup our font stack – We’ll use a nice sans-serif font stack
  • Remove/modify some browser defaults
body {
	background:#edf1f4 url(bg.jpg);
	font-family: "Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans serif;
	font-size:16px;
	color:#444;
}
ul, li {
	margin:0;
	padding:0;
	list-style-type:none;
}

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_4.jpg”> class=”alignnone size-full wp-image-28534″ title=”Step 4″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_4.jpg” alt=”Step 4 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 5: Create background style

Now we will style our main container and center it in the page. We’ll also applying some styles to our H1 tag.

#container {
	width:400px;
	padding:0px;
	background:#fefefe;
	margin:0 auto;
	border:1px solid #c4cddb;
	border-top-color:#d3dbde;
	border-bottom-color:#bfc9dc;
	box-shadow:0 1px 1px #ccc;
	border-radius:5px;
	position:relative;
}
h1 {
	margin:0;
	padding:10px 0;
	font-size:24px;
	text-align:center;
	background:#eff4f7;
	border-bottom:1px solid #dde0e7;
	box-shadow:0 -1px 0 #fff inset;
	border-radius:5px 5px 0 0; /* otherwise we get some uncut corners with container div */
	text-shadow:1px 1px 0 #fff;
}

It’s important to note that we have to give our H1 tag a border radius on its top two corners. If we don’t, the H1′s background color will overlap the rounded corners of it’s parent element (#container) and it will look like this:

class=”alignnone size-full wp-image-28537″ title=”Step 5″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step5_2.jpg” alt=”Step 5 Screenshot” width=”615″ height=”475″ />

Adding border-radius to the H1 element assures our top corners will remain rounded. Here’s what we have so far:

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_5.jpg”> class=”alignnone size-full wp-image-28535″ style=”border: 0px initial initial;” title=”Step 5″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step_5.jpg” alt=”Step 5 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 6: CSS styles for the form

Now let’s style our various form elements starting with the list elements inside the form:

form ul li {
	margin:10px 20px;

}
form ul li:last-child {
	text-align:center;
	margin:20px 0 25px 0;

We used the :last-child selector to select the last item in the list (button) and give it some extra spacing. (Note this selector is not supported in some legacy browsers). Next, let’s style our input elements:

input {
	padding:10px 10px;
	border:1px solid #d5d9da;
	border-radius:5px;
	box-shadow: 0 0 5px #e8e9eb inset;
	width:328px; /* 400 (#container) - 40 (li margins) -  10 (span paddings) - 20 (input paddings) - 2 (input borders) */
	font-size:1em;
	outline:0; /* remove webkit focus styles */
}
input:focus {
	border:1px solid #b9d4e9;
	border-top-color:#b6d5ea;
	border-bottom-color:#b8d4ea;
	box-shadow:0 0 5px #b9d4e9;

Notice that we calculated our input element’s width by taking the #container width (400px) and subtracting the margins, paddings, and borders applied to the input’s parent elements. We also used the outline property to remove the default WebKit focus styles. Lastly let’s apply some styles to our other form elements:

label {
	color:#555;
}
#container span {
	background:#f6f6f6;
	padding:3px 5px;
	display:block;
	border-radius:5px;
	margin-top:5px;
}

Now we have something that looks like this:

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step6.jpg”> class=”alignnone size-full wp-image-28539″ title=”Step 6″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step6.jpg” alt=”Step 6 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 7: Button Styles

Now we are going to style our button element. We’ll use some CSS3 styles so users with newer browsers get a better experience. If you’re looking for a great resource when creating background gradients in CSS3, check out href=”http://www.colorzilla.com/gradient-editor/”>Ultimate CSS Gradient Generator.

button {
	background: #57a9eb; /* Old browsers */
	background: -moz-linear-gradient(top, #57a9eb 0%, #3a76c4 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#57a9eb), color-stop(100%,#3a76c4)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, #57a9eb 0%,#3a76c4 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, #57a9eb 0%,#3a76c4 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, #57a9eb 0%,#3a76c4 100%); /* IE10+ */
	background: linear-gradient(top, #57a9eb 0%,#3a76c4 100%); /* W3C */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#57a9eb', endColorstr='#3a76c4',GradientType=0 ); /* IE6-9 */
	border:1px solid #326fa9;
	border-top-color:#3e80b1;
	border-bottom-color:#1e549d;
	color:#fff;
	text-shadow:0 1px 0 #1e3c5e;
	font-size:.875em;
	padding:8px 15px;
	width:150px;
	border-radius:20px;
	box-shadow:0 1px 0 #bbb, 0 1px 0 #9cccf3 inset;
}
button:active {
	background: #3a76c4; /* Old browsers */
	background: -moz-linear-gradient(top, #3a76c4 0%, #57a9eb 100%); /* FF3.6+ */
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3a76c4), color-stop(100%,#57a9eb)); /* Chrome,Safari4+ */
	background: -webkit-linear-gradient(top, #3a76c4 0%,#57a9eb 100%); /* Chrome10+,Safari5.1+ */
	background: -o-linear-gradient(top, #3a76c4 0%,#57a9eb 100%); /* Opera 11.10+ */
	background: -ms-linear-gradient(top, #3a76c4 0%,#57a9eb 100%); /* IE10+ */
	background: linear-gradient(top, #3a76c4 0%,#57a9eb 100%); /* W3C */
	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3a76c4', endColorstr='#57a9eb',GradientType=0 ); /* IE6-9 */
	box-shadow:none;
	text-shadow:0 -1px 0 #1e3c5e;
}

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step7.jpg”> class=”alignnone size-full wp-image-28540″ title=”Step 7″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step7.jpg” alt=”Step 7 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 8: Password Information Box

Now we are going to style the box that informs users if they are meeting the password requirements. First, we will style the containing element (#pswd_info).

#pswd_info {
	position:absolute;
	bottom:-75px;
	bottom: -115px; /* IE Specific */
	right:55px;
	width:250px;
	padding:15px;
	background:#fefefe;
	font-size:.875em;
	border-radius:5px;
	box-shadow:0 1px 3px #ccc;
	border:1px solid #ddd;
}

Now let’s add some style to the H4 element:

#pswd_info h4 {
	margin:0 0 10px 0;
	padding:0;
	font-weight:normal;
}

Lastly, we are going to use the CSS ::before selector to add an “up-pointing triangle”. This is a geometric character which can be inserted using it’s corresponding UNICODE entity. Normally in HTML you would use the character’s HTML entity (&#9650;). However, because we are adding it in CSS, we must use the UNICODE value (25B2) preceded by a backslash.

#pswd_info::before {
	content: "B2";
	position:absolute;
	top:-12px;
	left:45%;
	font-size:14px;
	line-height:14px;
	color:#ddd;
	text-shadow:none;
	display:block;
}

Now we have this:

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step8.jpg”> class=”alignnone size-full wp-image-28541″ title=”Step 8″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step8.jpg” alt=”Step 8 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 9: Valid and invalid states

Let’s add some styles to our requirements. If the requirement has been met, we’ll give it a class of “valid”. If it hasn’t been met, it will get a class of “invalid” (default class). As for the icons, I am using two 16×16 pixel icons from the href=”http://www.famfamfam.com/lab/icons/silk/”>Silk Icon Set.

.invalid {
	background:url(../images/invalid.png) no-repeat 0 50%;
	padding-left:22px;
	line-height:24px;
	color:#ec3f41;
}
.valid {
	background:url(../images/valid.png) no-repeat 0 50%;
	padding-left:22px;
	line-height:24px;
	color:#3a7d34;
}

Because we haven’t included the JavaScript functionality that will dynamically change the “valid” and “invalid” classes, all requirements will appear as invalid (we’ll change this later). Here’s what we have so far:

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step9.jpg”> class=”alignnone size-full wp-image-28542″ title=”Step 9″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step9.jpg” alt=”Step 9 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Hide the Box

Now that we have everything styled exactly how we want it, we’re going to hide the password information box. We’ll toggle it’s visibility to the user using JavaScript. So let’s add the following rule:

#pswd_info {
	display:none;
}

class=”spacer_” />

Step 10: Grasping the scope

Here is what we want to accomplish with our script:

  • When the password field is selected (:focus), show it
  • Every time the user types a new character in the password field, check and see if that character fulfills one of the following password complexity rules:
    • At least one letter
    • At least one capital letter
    • At least one number
    • At least eight characters in length
  • If it does, mark that rule as “valid”
  • If it doesn’t, mark that rule as “invalid”
  • When the password field is not selected (‘:blur’), hide it

class=”spacer_” />

Step 11: Getting jQuery setup

First, we need to add jQuery to our page. We’ll use the hosted version. We also want to link to our “script.js” file, which is where we will write the code needed for our password verification test. So, add the following to your <head> tag:

<script src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script src="script.js"></script>

In our “script.js” file, we’ll start with some basic jQuery starter code for our script:

$(document).ready(function() {

	//code here

});

class=”spacer_” />

Step 12: Setting up the event triggers

Essentially we have three events we will be listening for:

  1. “Keyup” on the password input field /> (triggers whenever the user pushes a key on the keyboard)
  2. “Focus” on the password input field /> (triggers whenever the password field is selected by the user)
  3. “Blur” on the password input field /> (triggers whenever the password field is unselected)

As you can see, all the events we are listening for are on the password input field. In this example, we will select all input fields where the type is equal to password. jQuery also allows us to “chain” these events together, rather than typing out each one. So, for example, rather than typing this:

$('input[type=password]').keyup(function() {
	// keyup event code here
});
$('input[type=password]').focus(function() {
	// focus code here
});
$('input[type=password]').blur(function() {
	// blur code here
});

We can chain all the events together and type the following:

$('input[type=password]').keyup(function() {
	// keyup code here
}).focus(function() {
	// focus code here
}).blur(function() {
	// blur code here
});

So, with that knowledge, let’s create our code that will show or hide our password information box depending on whether the password input field is selected by the user or not:

$('input[type=password]').keyup(function() {
	// keyup code here
}).focus(function() {
	$('#pswd_info').show();
}).blur(function() {
	$('#pswd_info').hide();
});

You will now notice that by clicking in the password input field, the password information box will be visible. Likewise, by clicking outside the password input field, the password information box will be hidden.

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step12.jpg”> class=”alignnone size-full wp-image-28543″ title=”Step 12″ src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step12.jpg” alt=”Step 12 screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Step 13: Checking the complexity rules

All we need to do now is have the script check the value in the password field every time a new character is entered (using the ‘keyup’ event). So, inside the $('input[type=password]').keyup function we’ll add the following code:

// set password variable
var pswd = $(this).val();

This sets up a variable named ‘pswd’ that stores the current password field value every time there is a keyup event. We will use this value in checking each of our complexity rules.

class=”spacer_” />

Validating the length

Now, inside the same keyup function, let’s add the following:

//validate the length
if ( pswd.length < 8 ) {
	$('#length').removeClass('valid').addClass('invalid');
} else {
	$('#length').removeClass('invalid').addClass('valid');
}

This checks to see if the length of the current password value is smaller than 8 characters. If it is, it’s get an ‘invalid’ class. If it’s bigger than 8 characters, it gets a ‘valid’ class.

class=”spacer_” />

Validating with regular expressions

As you saw above, we simply have an if/else statement that tests to see if the complexity requirement has been met. If the complexity requirement is met, we give it’s ID in the password box a class of “valid”. If it is not met, it gets a class of “invalid”.

The rest of our requirements will require we use regular expressions to test the complexity rules. So, let’s add the following:

//validate letter
if ( pswd.match(/[A-z]/) ) {
	$('#letter').removeClass('invalid').addClass('valid');
} else {
	$('#letter').removeClass('valid').addClass('invalid');
}

//validate capital letter
if ( pswd.match(/[A-Z]/) ) {
	$('#capital').removeClass('invalid').addClass('valid');
} else {
	$('#capital').removeClass('valid').addClass('invalid');
}

//validate number
if ( pswd.match(/\d/) ) {
	$('#number').removeClass('invalid').addClass('valid');
} else {
	$('#number').removeClass('valid').addClass('invalid');
}

Here is an explanation of the three if/else statements we used:

[A-z]
This expressions checks to make sure at least one letter of A through Z (uppercase) or a through z (lowercase) has been entered
[A-Z]
This expressions checks to make sure at least one uppercase letter has been entered
\d
This will check for any digits 0 through 9

class=”spacer_” />

Step 14: Test it out

That’s all there is to it! You can add more to this if you want. You could add more complexity rules, you could add a submission method, or you could add whatever else you deem necessary.

href=”http://netdna.webdesignerdepot.com/uploads/2011/12/step141.jpg”> class=”alignnone size-full wp-image-28531″ title=”Final product” src=”http://netdna.webdesignerdepot.com/uploads/2011/12/step141.jpg” alt=”Final product screenshot” width=”615″ height=”475″ />

class=”spacer_” />

Jim Nielsen considers himself a web designer at heart, though he often dabbles in other areas such as print and identity design. He loves acquiring new knowledge from the ever-expanding disciplines of the web. You can follow his latest happenings at his website rel=”nofollow” href=”http://www.jim-nielsen.com” target=”_blank”>www.jim-nielsen.com


/>
width=”100%” style=”border-top:1px solid #d7d7d7; border-bottom:1px solid #d7d7d7;” height=”20″>
valign=”center”> href=”http://www.mightydeals.com/deal/vandelay-textures.html?ref=inwidget”> face=”Arial” size=”3″ color=”#e64f32″>250 High Res Textures from Vandelay Premier – only width=”90″> href=”http://www.mightydeals.com/?ref=inwidget”> /> src=”http://mightydeals.com/web/images/widget-logo.png” height=”40″ width=”90″ border=”0″ /> />


href=”http://www.webdesignerdepot.com/2012/01/password-strength-verification-with-jquery/”>Source




Webdesigner Depot


Short Musings On JavaScript MV* Tech Stacks

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about plugins

Lately, there have been a number of developers getting in touch to discuss the tech stacks for their web applications. In this short post, I'd like to focus on the JavaScript side of some of these conversations. We're at an … href=”http://addyosmani.com/blog/short-musings-on-javascript-mv-tech-stacks/”>Continue reading class=”meta-nav”>→
AddyOsmani.com | Articles for developers


Adventures In The Third Dimension: CSS 3D Transforms

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about css3





 



 


Back in 2009, the WebKit development team proposed a new extension to CSS that would allow Web page elements to be displayed and transformed on a three-dimensional plane. This proposal was called 3-D Transforms, and it was soon implemented in Safari for Mac and iOS. About a year later, support followed for Chrome, and early in 2011, for Android. Outside of WebKit, however, none of the other browser makers seemed to show much enthusiasm for it, so it’s remained a fairly niche and underused feature.

That’s set to change, though, as the Firefox and Internet Explorer teams have decided to join the party by implementing 3-D Transforms in pre-release versions of their browsers. So, if all goes according to plan, we’ll see them in IE 10 and a near-future version of Firefox (possibly 10 or 11, but that’s not confirmed yet), both of which are slated for release sometime this year.

That being the case, this is an ideal time to get ahead of the curve and start learning about the possibilities and potential of adding an extra dimension to your Web pages. This article aims to help you do just that, by taking you on a flying tour of the 3-D Transforms syntax.

Please bear in mind that in order to see the examples in this article, you’ll need a browser that supports 3-D Transforms; as I write this, that’s Safari, Chrome, IE 10 Platform Preview or Firefox Aurora.

The Third Dimension

On the Web, we’re accustomed to working in two dimensions: all elements have width and height, and we move them around the screen horizontally (left to right) and vertically (top to bottom). The move to a third dimension can be thought of as adding depth to elements, and adding movement towards and away from you (the viewer). Think about 3-D films in which objects are constantly thrust out of the screen towards you in an attempt to demonstrate the possibilities of the extra depth.

To use 3-D Transforms in CSS, you’ll need to know about axes (that’s the plural of axis, not the plural of axe). If you already know about working in three dimensions or remember using axes in math class at school, you can skip the next section. For everyone else, here is…

A Quick Primer On Axes

I just mentioned that on the 2-D Web, we move elements around horizontally and vertically. Each of these directions is called an axis: the horizontal line is known as the x-axis, and the vertical line is the y-axis. If we think of the top-left corner of an element as our origin (i.e. the point from which movement is measured), a movement to the left is a negative movement along the x-axis, and a move to the right is a positive movement along the x-axis. The same goes for moving an element up (negative on the y-axis) and down (positive on the y-axis).

The third dimension is known as the z-axis and, as I said, can be thought of as towards or away from you; a negative movement along the z-axis is away from you, and a positive movement is towards you.

screenshot
Showing the three axes: x (left-right), y (up-down) and z (away-towards).

If you’ve read all of this talk of axes and negative movements and you’re rubbing your eyes and blinking in disbelief and misunderstanding, don’t worry: it will all become clear when you get stuck in the code. Come back and read this again after a few examples and it should all be clear.

Transformation Functions

The various transformations are all applied with a single CSS property: transform — yes, the same property that’s used for 2-D CSS Transforms. At the moment, this property is still considered experimental, so remember to use all of the browser prefixes, like so:

div {
  -moz-transform: foo;
  -ms-transform: foo;
  -o-transform: foo;
  -webkit-transform: foo;
}

Note that Opera doesn’t currently have an implementation of 3-D Transforms, but I’m including it here because work is apparently underway. For the sake of clarity, in the examples throughout this article, I’ll use only non-prefixed properties, but remember to include all of the prefixed ones in your own code.

Anyway, the transform property accepts a range of functions as values, each of which applies a different transformation. If you’ve used 2-D CSS Transforms, then you’ll already know many of these functions because they are quite similar (or, in some cases, the same). Here are all of the 3-D functions:

  • matrix3d
  • perspective
  • rotateX, rotateY, rotateZ, rotate3d
  • scaleX, scaleY, scaleZ, scale3d
  • translateX, translateY, translateZ, translate3d

Now, matrix3d definitely sounds the coolest, but it’s so unbelievably complex (it takes 16 values!) that there’s no way I could cover it in this article. So, let’s put that aside and take a quick look at the others.

Rotation

To explain what this does, I’ll have to ask you to do a little mental exercise (which will come in useful later in the article, too). Imagine a sheet of card with a string running through the middle that fixes it in place. By taking the top corners in your fingers, you can move the card up and down, left and right, and forwards and backwards, pivoting around the string. This is what the rotate() function does. The individual functions rotateX(), rotateY() and rotateZ() take a deg (i.e. degree) value and move the element around its point of origin (where the string passes through it) by that much.

Have a look at our first example (a screenshot is shown below in case you don’t have access to a supported browser). Here we’ve rotated each of the elements 45° around a different axis (in order: x, y, z), so you can see the effect of each. The semi-translucent red box shows the original position of the element, and if you mouse over each, you’ll see the transformations removed (I’ve used this convention in all of the examples in this article).

screenshot
Each element is rotated 45° around a different axis: x (left), y (center) and z (right).

There is a rotate3d() function as well, but it’s too complex to explain in a brief article like this one, so we’ll skip it.

Translation

This is really just a fancy way of saying “movement.” The functions translateX(), translateY() and translateZ() each take a length value, which moves the element by that distance along the given axis. So, translateX(2em) would move the element 2 ems to the right, and translateZ(-10px) would move the element 10 pixels away from the viewer. There’s also a shorthand function, translate3d(), which takes three values in order, one for each axis, like so: translate3d(x, y, z).

In our second example, we’ve translated each of the elements by -20 pixels along a different axis (in order: x, y, z).

screenshot
Each element is translated by -20 pixels along a different axis: x (left), y (center) and z (right).

Note that translation of an element is similar to relative positioning, in that it doesn’t affect the document’s flow. The translated element will keep its position in the flow and will only appear to have moved, meaning it might cover or show through surrounding elements.

Scaling

This just means making bigger or smaller. The three functions scaleX(), scaleY() and scaleZ() each take a unitless number value, which is used as a multiplier. For scaleX() and scaleY(), this is applied directly to the width and height; for example, applying scaleY(1.5) to an element with a height of 100 pixels would transform it to 150 pixels high, and applying scaleX(0.75) to an element with a width of 100 pixels would transform it to 75 pixels wide.

The scaleZ() function behaves slightly differently. Transformed elements don’t actually have any depth to increase or decrease; what we’re doing is more like moving a 2-D object around in 3-D space. Instead, the value given to scaleZ() acts as a multiplier for the translateZ() function that I explained in the last section. So, applying both translateZ(10px) and scaleZ(2) would translate an element 20 pixels along the z-axis.

There’s also a shorthand property, scale3d(), which, like translate3d(), takes three values, one for each of the individual functions: scale3d(x,y,z). So, in the following code example, the same transformation applies to both of the elements:

.e1 {
   transform: scaleX(1.5) scaleY(1.5) scaleZ(0.75);
}

.e2 {
   transform: scale3d(1.5,1.5,0.75);
}

Perspective

The perspective() function is quite simple, but what it actually does is quite complex. The function takes a single value, which is a whole number greater than 0 (zero). Explaining this is a little complicated; the number is like a distance between you and the object that you’re viewing (a tutorial on Eleqtriq has a more technical explanation and diagram). For our purposes, you just need to know that the lower the number, the more extreme the 3-D effect will appear; any value below 200 will make the transformation appear very exaggerated, and any value of 1000 or more will seem to have no effect at all.

In our third example, we have three transformed elements, each with a different value for the perspective() function: 25, 50 and 200, respectively. Although the difference between the three is very discernible, it’s even clearer when you mouse over to see the transformations removed.

screenshot
Each element has a different value for the perspective() function: 25 (left), 50 (center) and 200 (right).

Note that I’ve transformed the parent elements (equally) so that we can see the degree of perspective more clearly; sometimes the difference in perspective values can be imperceptible.

Other Properties

In addition to Transform, you’ll need to know about a few other important properties.

transform-style

If you’ll be applying 3-D transformations to the children of an already transformed element, then you’ll need to use this property with the value preserve-3d (the alternative, and default, is flat). This means that the child elements will appear on their own planes; without it, they would appear flat in front of their parent.

Our fourth example clearly illustrates the difference; the element on the left has the flat value, and on the right, preserve-3d.

screenshot
The element on the left has a transform-style value of flat, and the one on the right has a value of preserve-3d.

Something else to note is that if you are transforming child elements, the parent must not have an overflow value of hidden; this would also force the children into appearing on the same plane.

transform-origin

As mentioned, when you apply a transformation to an element, the change is applied around a point directly in the horizontal and vertical middle — like the imaginary piece of string we saw in the earlier illustration. Using transform-origin, you can change this to any point in the element. Acceptable values are pairs of lengths, percentages or positional keywords (top, right, etc.). For example:

div {
   transform-origin: right top;
}

In our fifth example, you can see the same transformations applied to two elements, each of which has a different transform-origin value.

screenshot
The element on the left has a transform-origin value of center center, and the one on the right has a value of right top.

The difference is clearly visible, but even more obvious if you pass the mouse over to see the transformation removed.

backface-visibility

Depending on which transformation functions you apply, sometimes you will move an element around until its front (or “face”) is angled away from you. When this happens, the default behavior is for the element to be shown in reverse; but if you use backface-visibility with a value of hidden, you’ll see nothing instead, not even a background color.

perspective and perspective-origin

We introduced the perspective() function earlier, but the perspective property takes the same values; the difference is that the property applies only to the children of the element that it’s used on, not the element itself.

The perspective-origin property changes the angle from which you view the element that’s being transformed. Like transform-origin, it accepts lengths, percentages or positional keywords, and the default position is the horizontal and vertical middle. The effect of changing the origin will be more pronounced the lower the perspective value is.

Conclusion

By necessity, we’ve flown through the intricacies of the 3-D transformations syntax, but hopefully I’ve whetted your appetite to try it out yourself. With a certain amount of care for older browser versions, you can implement these properties in your own designs right now. If you don’t believe me, compare the list of “More adventures” on The Feed website that I built last year in a browser that supports 3-D transforms and in one that doesn’t, and you’ll see what I mean.

Some of the concepts used in 3-D transforms can be quite daunting, but experimentation will soon make them clear to you in practice, so get ahold of a browser that supports them and start making some cool stuff. But please, be responsible: not everything on the Web needs to be in three dimensions!

Further Reading and Resources

  • The Bright (Near) Future of CSS
    Eric Meyer’s comprehensive article on CSS3, covering CSS3 3D Transforms as well.
  • 3D Transforms, Westciv
    This tool lets you play around with different transformation values and shows you the result in real time.
  • CSS3 3D Transforms,” W3C
    The CSS 3D Transforms module is the full specification, although it is very dry and technical.
  • 20 Stunning Examples of CSS 3D Transforms,” Paul Hayes
    See what you can build when you master 3-D Transforms.
  • The Book of CSS3, Peter Gasston
    My book contains much more detail about all of the functions that I’ve covered in this article, as well as the ones I had to leave out.

(al)


© Peter Gasston for Smashing Magazine, 2012.

Smashing Magazine Feed


Comics of the week #111

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about photoshop

href=”http://netdna.webdesignerdepot.com/uploads/2011/11/thumb19.jpg”> class=”alignleft size-full wp-image-27877″ title=”thumb” src=”http://netdna.webdesignerdepot.com/uploads/2011/11/thumb19.jpg” alt=”" width=”200″ height=”160″ />Every week we feature a set of comics created exclusively for WDD.

The content revolves around web design, blogging and funny situations that we encounter in our daily lives as designers.

These great cartoons are created by Jerry King, an style=”font-family: Verdana,Arial,Helvetica,sans-serif; color: #081852; font-size: x-small;”> award-winning cartoonist who’s one of the most published, prolific and versatile cartoonists in the world today.

So for a few moments, take a break from your daily routine, have a laugh and enjoy these funny cartoons.

Feel free to leave your comments and suggestions below as well as any related stories of your own… id=”more-27873″>

Red text

href=”http://netdna.webdesignerdepot.com/uploads/2011/11/61.jpg”> class=”image-border” title=”6″ src=”http://netdna.webdesignerdepot.com/uploads/2011/11/61.jpg” alt=”" width=”615″ height=”450″ />

class=”spacer_” />

Undersold designer

href=”http://netdna.webdesignerdepot.com/uploads/2011/11/111.jpg”> class=”image-border” title=”11″ src=”http://netdna.webdesignerdepot.com/uploads/2011/11/111.jpg” alt=”" width=”615″ height=”450″ />

class=”spacer_” />

Pink man cave

href=”http://netdna.webdesignerdepot.com/uploads/2011/11/121.jpg”> class=”image-border” title=”12″ src=”http://netdna.webdesignerdepot.com/uploads/2011/11/121.jpg” alt=”" width=”615″ height=”450″ />

Can you relate to these situations? Please share your funny stories and comments below…

/>


/>
width=”100%” style=”border-top:1px solid #d7d7d7; border-bottom:1px solid #d7d7d7;” height=”20″>
valign=”center”> href=”http://www.mightydeals.com/deal/john-forsythes-photoshop-text-effects.html?ref=inwidget”> face=”Arial” size=”3″ color=”#e64f32″>Over 1,500 Professional Photoshop Text Effects – only ! width=”90″> href=”http://www.mightydeals.com/?ref=inwidget”> /> src=”http://mightydeals.com/web/images/widget-logo.png” height=”40″ width=”90″ border=”0″ /> />


href=”http://www.webdesignerdepot.com/2012/01/comics-of-the-week-111/”>Source




Webdesigner Depot


Launching soon: The Webdesigner Depot Newsletter

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about photoshop

href=”http://netdna.webdesignerdepot.com/uploads/2012/01/newsletter.jpg”> class=”alignleft size-full wp-image-28697″ title=”newsletter” src=”http://netdna.webdesignerdepot.com/uploads/2012/01/newsletter.jpg” alt=”" width=”200″ height=”160″ />For over three years, you have relied on Webdesigner Depot for quality articles, editorials, inspirational posts and an array of other cool stuff. Now, we’re adding a new layer to WDD by launching our own newsletter and you’re the first to know about it today!

Needless to say, we’re super thrilled and pumped about this!!… but you may wonder how’s this different to the WDD blog? The content! This is not your typical newsletter, with the same posts you’ll find on our site, or in our RSS feed.

Inside, you will find quality tips, exclusive downloads, news, tutorials and access to things you don’t get on the blog, which are exclusive to our subscribers and yes, it’s all 100% FREE, so you have nothing to lose and everything to gain!

The newsletter will be sent only once a month at first and in the future we may send out a few more per month, but don’t worry, we won’t spam you or overwhelm you with constant emails. Your email will be safe with us, it will never be sold or rented to any third party companies. If we do increase the frequency, we’ll also add an option to choose how often you want to hear from us.

Just sign up below for FREE and click on the confirmation link that will be sent to you: id=”more-28663″>

class=”post-wdd-newsletter-form”>


/>
width=”100%” style=”border-top:1px solid #d7d7d7; border-bottom:1px solid #d7d7d7;” height=”20″>
valign=”center”> href=”http://www.mightydeals.com/deal/youeye-user-testing.html?ref=inwidget”> face=”Arial” size=”3″ color=”#e64f32″>USER TESTING: Videos of REAL PEOPLE using your site – save 67%! width=”90″> href=”http://www.mightydeals.com/?ref=inwidget”> /> src=”http://mightydeals.com/web/images/widget-logo.png” height=”40″ width=”90″ border=”0″ /> />


href=”http://www.webdesignerdepot.com/2012/01/launching-soon-the-webdesigner-depot-newsletter/”>Source




Webdesigner Depot


How To Create Custom Taxonomies In WordPress

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about css3





 



 


WordPress 3 introduced custom taxonomies as a core feature. The following release of 3.1 included many features to enhance support of custom taxonomies. Better import and export handling, advanced queries with tax_query, hierarchical support, body classes and a bunch of wonderful functions to play with were all part of the package.

Let’s take an in-depth look at how to create your own custom taxonomies in WordPress, including a few advanced development examples that you can begin using in your WordPress themes and plugins today.

Taxonomies: Bringing order to chaos in WordPress

Taxonomies In WordPress

WordPress’ custom taxonomies make it possible to structure large amounts of content in a logical, well-organized way. In WordPress, categories are set up as a hierarchal taxonomy, and tags are set up as a multifaceted taxonomy.

Taxonomy content can be displayed in a theme using taxonomy templates. Within a template, there are ample ways to display your data with built-in taxonomy functions.

Built-In Taxonomies

WordPress offers four built-in taxonomies out of the box:

  1. Categories (hierarchal),
  2. Tags (multifaceted),
  3. Links (multifaceted),
  4. Navigation menu (hierarchal).

Custom Taxonomies

WordPress provides a new method of grouping content by allowing you to create your own custom taxonomies. The core developers have created the register_taxonomy() function to handle the heavy lifting for us. All you have to do is understand how to configure all of the settings to suit your needs.

A Practical Example: Content By Location

A business that operates in multiple locations could benefit from organizing its content by location to allow visitors to browse news in their locality. A large news organization could organize its content by world region (Africa, Asia, Europe, Latin America, Middle East, US & Canada), as the BBC does in its “World” section.

How the BBC uses a location taxonomy

Create a Custom Taxonomy

In WordPress, you can create (or “register”) a new taxonomy by using the register_taxonomy() function. Each taxonomy option is documented in detail in the WordPress Codex.

WordPress custom taxonomy: Posts by location

/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * http://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
	// Add new "Locations" taxonomy to Posts
	register_taxonomy('location', 'post', array(
		// Hierarchical taxonomy (like categories)
		'hierarchical' => true,
		// This array of options controls the labels displayed in the WordPress Admin UI
		'labels' => array(
			'name' => _x( 'Locations', 'taxonomy general name' ),
			'singular_name' => _x( 'Location', 'taxonomy singular name' ),
			'search_items' =>  __( 'Search Locations' ),
			'all_items' => __( 'All Locations' ),
			'parent_item' => __( 'Parent Location' ),
			'parent_item_colon' => __( 'Parent Location:' ),
			'edit_item' => __( 'Edit Location' ),
			'update_item' => __( 'Update Location' ),
			'add_new_item' => __( 'Add New Location' ),
			'new_item_name' => __( 'New Location Name' ),
			'menu_name' => __( 'Locations' ),
		),
		// Control the slugs used for this taxonomy
		'rewrite' => array(
			'slug' => 'locations', // This controls the base slug that will display before each term
			'with_front' => false, // Don't display the category base before "/locations/"
			'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
		),
	));
}
add_action( 'init', 'add_custom_taxonomies', 0 );

After adding this to your theme’s functions.php file, you should see a new taxonomy under the “Posts” menu in the admin sidebar. It works just like categories but is separate and independent.

WordPress custom taxonomy: Posts by location

After adding a few terms to your new taxonomy, you can begin to organize the content in your posts by location. A new “Locations” box will appear to the right of your posts in the WordPress admin area. Use this the way you would categories.

Let’s use this “location” taxonomy as a jumping-off point to learn more about working with taxonomy functions and content.

Create a Taxonomy Template for Your Theme

Taxonomies: Bringing order to chaos in WordPress

When you add a custom taxonomy to a WordPress theme, you can display its content using one of WordPress’ taxonomy theme templates.

  • taxonomy-{taxonomy}-{slug}.php
    We could use this to create a theme template for a particular location, such as taxonomy-location-boston.php for the term “boston.”
  • taxonomy-{taxonomy}.php
    If the taxonomy were location, WordPress would look for taxonomy-location.php.
  • taxonomy.php
    This template is used for all custom taxonomies.
  • archive.php
    If no taxonomy-specific template is found, then the taxonomy that lists pages will use the archive template.
  • index.php
    If no other template is found, then this will be used.

Let’s use taxonomy-location.php to display our content. The template file could look something like this:

<?php
/**
 * Locations taxonomy archive
 */
get_header();
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
?>
<div class="wrapper">
	<div class="primary-content">
		<h1 class="archive-title"><?php echo apply_filters( 'the_title', $term->name ); ?> News</h1>

		<?php if ( !empty( $term->description ) ): ?>
		<div class="archive-description">
			<?php echo esc_html($term->description); ?>
		</div>
		<?php endif; ?>

		<?php if ( have_posts() ): while ( have_posts() ): the_post(); ?>

		<div id="post-<?php the_ID(); ?>" <?php post_class('post clearfix'); ?>>
			<h2 class="post-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
			<div class="content clearfix">
				<div class="post-info">
					<p><?php the_time(get_option('date_format')); ?> by <?php the_author_posts_link(); ?></p>
				</div><!--// end .post-info -->
				<div class="entry">
					<?php the_content( __('Full story…') ); ?>
				</div>
			</div>
		</div><!--// end #post-XX -->

		<?php endwhile; ?>

		<div class="navigation clearfix">
			<div class="alignleft"><?php next_posts_link('« Previous Entries') ?></div>
			<div class="alignright"><?php previous_posts_link('Next Entries »') ?></div>
		</div>

		<?php else: ?>

		<h2 class="post-title">No News in <?php echo apply_filters( 'the_title', $term->name ); ?></h2>
		<div class="content clearfix">
			<div class="entry">
				<p>It seems there isn't anything happening in <strong><?php echo apply_filters( 'the_title', $term->name ); ?></strong> right now. Check back later, something is bound to happen soon.</p>
			</div>
		</div>

		<?php endif; ?>
	</div><!--// end .primary-content -->

	<div class="secondary-content">
		<?php get_sidebar(); ?>
	</div><!--// end .secondary-content -->

<?php get_footer(); ?>

(Normally, we would load a template part for the loop, but for the sake of simplicity, I’ve skipped that step. As an alternative to get_term_by(), we could use single_term_title() and term_description() on this taxonomy archive template to display or retrieve the title and description of the taxonomy term.)

In this example, we’ve used a function called get_term_by() to retrieve all of the data associated with a taxonomy term in the form of an object. The object returned by the get_term_by() function contains the following details about the term:

  • ID
    325
  • name
    Boston
  • slug
    boston
  • group
    0
  • taxonomy
    location
  • taxonomy ID
    325
  • description
    If you need to know the latest news in Boston, then look no further.
  • parent
    0 (or the ID)
  • count
    1 (i.e. the number of posts with this term selected)

We’ve used this object, then, to display information about the current term name and description in the taxonomy-location.php template.

Using Taxonomy Conditionals

Conditional tags can be used in WordPress to determine what content is displayed on a particular page depending on the conditions met by the page. Taxonomy templates have their own set of conditionals:

  • is_tax()
    When any taxonomy archive page is being displayed.
  • is_tax( 'location' )
    When a taxonomy archive page for the “location” taxonomy is being displayed.
  • is_tax( 'location', 'boston')
    When the archive page for the “location” taxonomy with the slug of “boston” is being displayed.
  • is_tax( 'location', array( 'boston', 'new-york', 'philadelphia' ) )
    Returns true when the “location” taxonomy archive being displayed has a slug of either “boston,” “new-york” or “philadelphia.”
  • taxonomy_exists()
    When a particular taxonomy is registered via register_taxonomy().

Working With Taxonomy Functions

Many functions for working with taxonomies are available in WordPress. Let’s go through a few commons examples of how to use them in practice.

Display a List of Taxonomy Terms

Most navigation systems begin with an unordered list. You can generate an unordered list of links to taxonomy archive pages using the wp_list_categories() function. This function is very customizable and can handle most of the scenarios that you’ll encounter as a theme developer.

/**
 * Create an unordered list of links to active location archives
 */
$locations_list = wp_list_categories( array(
  'taxonomy' => 'location',
  'orderby' => 'name',
  'show_count' => 0,
  'pad_counts' => 0,
  'hierarchical' => 1,
  'echo' => 0,
  'title_li' => 'Locations'
) );

// Make sure there are terms with articles
if ( $locations_list )
	echo '<ul class="locations-list">' . $locations_list . '</ul>';

If you encounter a situation that requires a custom structure, I would recommend exploring the Walker class or the wp_get_object_terms() function.

Create a Taxonomy Tag Cloud

A tag cloud provides a great way for users to browse content. The wp_tag_cloud() function makes creating a tag cloud with a custom taxonomy easy.

WordPress taxonomy term cloud example

Let’s use it to display a tag cloud of our location terms:

// Locations tag cloud
<?php
$locations_cloud = wp_tag_cloud( array(
	'taxonomy' => 'location',
	'echo' => 0
) );

// Make sure there are terms with articles
if ( $locations_cloud ): ?>
<h2>News by Location</h2>
<div class="locations-cloud">
	<?php echo $locations_cloud; ?>
</div>
<?php endif; ?>

Get All Terms in a Taxonomy

You will often need to work with a full list of terms in a taxonomy, and the get_terms() function can be quite handy for this. Let’s use it to show off the number of locations to which we’re providing news:

<?php
// Get a list of all terms in a taxonomy
$terms = get_terms( "location", array(
	'hide_empty' => 0,
) );
$locations = array();
if ( count($terms) > 0 ):
	foreach ( $terms as $term )
		$locations[] = $term->name;

	$locations_str = implode(', ', $locations);
?>
<h2>Nationwide Coverage</h2>
<p>We cover stories around the country in places like <?php echo $locations_str; ?> and more. If we're not the best source for the latest news in your area, let us know!</p>
<?php endif; ?>

This will output the following HTML:

<h2>Nationwide Coverage</h2>
<p>We cover stories around the country in places like Boston, London, New York, San Francisco and more. If we're not the best source for the latest news in your area, let us know!</p>

This simple approach may not show it, but the get_terms() function is incredibly powerful. It allows you to get terms from multiple taxonomies at once by passing an array that contains the names of your taxonomies as the first parameter.

Working With WP_Query and tax_query

The WP_Query class enables you to create a custom loop. WordPress 3.1 introduced a new parameter for the class called tax_query, which allows you to display content from a taxonomy in many unique ways.

Let’s use it to create a list of the most recent news posts in Boston.

<?php
/**
 * Display a list of the most recent news in Boston
 *
 * @class WP_Query http://codex.wordpress.org/Class_Reference/WP_Query
 */
$locations_query = new WP_Query( array(
	'post_type' => 'post',
	'posts_per_page' => 10,
	'tax_query' => array(
		array(
			'taxonomy' => 'location',
			'field' => 'slug',
			'terms' => 'boston'
		)
	)
) );
// Display the custom loop
if ( $locations_query->have_posts() ): ?>
<h2>Latest News in Boston</h2>
<ul class="postlist">
	<?php while ( $locations_query->have_posts() ) : $locations_query->the_post(); ?>
	<li><span class="date"><?php the_time(get_option('date_format')); ?></span> – <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></li>
	<?php endwhile; wp_reset_postdata(); ?>
</ul><!--// end .postlist -->
<?php endif; ?>

We could easily make this set-up dynamic by using the get_term_by() or get_terms() functions that we discussed earlier.

Attaching Additional Data to a Taxonomy

Each taxonomy term has specific data associated with it. Out of the box, WordPress allows you to store the following information for each taxonomy term:

  • Name,
  • Slug,
  • Parent,
  • Description.

But what if you need to store more information, such as an image for the taxonomy term or a title and description for search engines, or maybe even attach the term to a particular author the way a traditional news column does? Since WordPress 2.9, developers have been able to attach additional meta data to posts, pages, custom post types, comments and users using the add_metadata(), update_metadata() and get_metadata() functions. But this does not include taxonomies such as tags and categories.

With the help of the Taxonomy Metadata plugin, we can attach meta data to taxonomy terms for both built-in and custom taxonomies. This enables us to create additional taxonomy fields that will be stored in a new taxonomymeta database table.

Note to Multisite developers: I’ve encountered issues using the Taxonomy Metadata plugin on a WordPress Multisite installation. Activating the plugin network-wide results in data not being saved. Instead, activate the plugin individually for each website, and it will work properly.

(Knowing the story behind this technique and what it might mean for future WordPress upgrades is important. Currently, there is a debate on the WordPress Trac project about the best method for this. The method I’ll show you is one suggested by various WordPress core developers. But I strongly urge you to review the Trac project and the Codex. A standard approach could very well be built into WordPress in the future, which would therefore be more practical than what I am about to show you.)

The prerequisite to all of the examples below is to install and activate the Taxonomy Metadata plugin.

Add Search Engine Title and Description Fields to Categories and Tags

We will use action hooks to gracefully attach additional fields to our taxonomies without editing WordPress’ core. If you’ve made it this far, then you probably have a working knowledge of WordPress filters and actions. To learn about working with hooks, I highly suggest Daniel Pataki’s article on the subject.

WordPress taxonomy meta data: Search engine title and description fields added to categories and tags

Let’s start by adding a text input and a textarea field to the “Add New” and “Edit” term pages on the WordPress admin screen. We do this by placing the following functions in our theme or plugin.

The taxonomy_metadata_add() function attaches the fields to the /wp-admin/edit-tags.php?taxonomy=%taxonomy% page.
The %taxonomy% item in the URL above will change depending on the term you are editing.

/**
 * Add additional fields to the taxonomy add view
 * e.g. /wp-admin/edit-tags.php?taxonomy=category
 */
function taxonomy_metadata_add( $tag ) {
	// Only allow users with capability to publish content
	if ( current_user_can( 'publish_posts' ) ): ?>
	<div class="form-field">
		<label for="meta_title"><?php _e('Search Engine Title'); ?></label>
		<input name="meta_title" id="meta_title" type="text" value="" size="40" />
		<p class="description"><?php _e('Title display in search engines is limited to 70 chars'); ?></p>
	</div>

	<div class="form-field">
		<label for="meta_description"><?php _e('Search Engine Description'); ?></label>
		<textarea name="meta_description" id="meta_description" rows="5" cols="40"></textarea>
		<p class="description"><?php _e('The meta description will be limited to 156 chars by search engines.'); ?></p>
	</div>
	<?php endif;
}

The taxonomy_metadata_edit() function attaches the fields to the /wp-admin/edit-tags.php?action=edit&taxonomy=%taxonomy%&tag_ID=%id%&post_type=%post_type% page.
The %taxonomy%, %id% and %post_type% items in the URL above will change depending on the term you are editing.

We’ll use the get_metadata function here to display any saved data that exists in the form.

/**
 * Add additional fields to the taxonomy edit view
 * e.g. /wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=27&post_type=post
 */
function taxonomy_metadata_edit( $tag ) {
	// Only allow users with capability to publish content
	if ( current_user_can( 'publish_posts' ) ): ?>
	<tr class="form-field">
		<th scope="row" valign="top">
			<label for="meta_title"><?php _e('Search Engine Title'); ?></label>
		</th>
		<td>
			<input name="meta_title" id="meta_title" type="text" value="<?php echo get_term_meta($tag->term_id, 'meta_title', true); ?>" size="40" />
			<p class="description"><?php _e('Title display in search engines is limited to 70 chars'); ?></p>
		</td>
	</tr>

	<tr class="form-field">
		<th scope="row" valign="top">
			<label for="meta_description"><?php _e('Search Engine Description'); ?></label>
		</th>
		<td>
			<textarea name="meta_description" id="meta_description" rows="5" cols="40"><?php echo get_term_meta($tag->term_id, 'meta_description', true); ?></textarea>
			<p class="description"><?php _e('Title display in search engines is limited to 70 chars'); ?></p>
		</td>
	</tr>
	<?php endif;
}

These two functions control the output of the form fields. I’ve used HTML that follows WordPress’ UI patterns and styles guidelines for the admin area.

Saving the form’s data to the taxonomymeta database table
Now that we’ve added the form fields, we’ll need to process and save the data with the update_term_meta function that is provided by the plugin.

/**
 * Save taxonomy metadata
 *
 * Currently the Taxonomy Metadata plugin is needed to add a few features to the WordPress core
 * that allow us to store this information into a new database table
 *
 *	http://wordpress.org/extend/plugins/taxonomy-metadata/
 */
function save_taxonomy_metadata( $term_id ) {
	if ( isset($_POST['meta_title']) )
		update_term_meta( $term_id, 'meta_title', esc_attr($_POST['meta_title']) );

	if ( isset($_POST['meta_description']) )
		update_term_meta( $term_id, 'meta_description', esc_attr($_POST['meta_description']) );
}

Add the new taxonomy fields
Now that everything is in place, we’ll use action hooks to load our new functions in all the right places. By hooking the following function into the admin_init action, we ensure that it runs only on the admin side of WordPress. First, we need to make sure that the functions added by the Taxonomy Metadata plugin are available. Next, we use the get_taxonomies() function to attach the new taxonomy fields to every public taxonomy, including the built-in tags and categories.

/**
 * Add additional taxonomy fields to all public taxonomies
 */
function taxonomy_metadata_init() {
	// Require the Taxonomy Metadata plugin
	if( !function_exists('update_term_meta') || !function_exists('get_term_meta') ) return false;

	// Get a list of all public custom taxonomies
	$taxonomies = get_taxonomies( array(
		'public'   => true,
		'_builtin' => true
	), 'names', 'and');

	// Attach additional fields onto all custom, public taxonomies
	if ( $taxonomies ) {
		foreach ( $taxonomies  as $taxonomy ) {
			// Add fields to "add" and "edit" term pages
			add_action("{$taxonomy}_add_form_fields", 'taxonomy_metadata_add', 10, 1);
			add_action("{$taxonomy}_edit_form_fields", 'taxonomy_metadata_edit', 10, 1);
			// Process and save the data
			add_action("created_{$taxonomy}", 'save_taxonomy_metadata', 10, 1);
			add_action("edited_{$taxonomy}", 'save_taxonomy_metadata', 10, 1);
		}
	}
}
add_action('admin_init', 'taxonomy_metadata_init');

That’s it. We’re done!

You should now see two additional fields in your tags, categories and public custom taxonomies. As mentioned at the beginning of this section, the technique can be used to handle many different scenarios. This basic framework for storing and retrieving information associated with a taxonomy should have you well on your way to mastering the management of taxonomy content.

In Conclusion

I hope you better understand how to organize WordPress content with the help of taxonomies. Whether hierarchal or multifaceted, a well-implemented taxonomy will simplify the way content is organized and displayed on a website. WordPress has all of the tools you need to create custom taxonomies and to group your content in new and exciting ways. How you use them is up to you!

Additional Resources

(al)


© Kevin Leary for Smashing Magazine, 2012.

Smashing Magazine Feed


jQuery UI Bootstrap – A New Bootstrap-inspired Theme For Your Widgets

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about plugins

I recently released the first version of a new project called jQuery UI Bootstrap – a Twitter Bootstrap inspired theme for UI widgets. For a demo of the theme or to download it, hop on over to the project homepage. … href=”http://addyosmani.com/blog/jquery-ui-bootstrap/”>Continue reading class=”meta-nav”>→
AddyOsmani.com | Articles for developers


Create a glowing blue-print style text effect in Photoshop

Posted on by Portsmouth Media in Blog Leave a comment

An article I was reading about jquery

n this tutorial, you will learn how to create a glowing and blue-print style typography effect in Photoshop using very simple and effective techniques.

Advertise here via BSA


Good-Tutorials: Newest Tutorials