Roots WordPress Theme Customization: Getting Started

Feb 21, 2013Hi everyone —

Roots has changed so much I need to re-work these tutorials. I hope to clear the space and start cranking them out soon. If you’d like, sign up for email notifications in the sidebar, so you’ll be notified when I’ve begun rolling them out again!

If you’ve not yet seen the excellent Roots Theme for WordPress, take a look. It brings to WordPress theme development the benefits of the HTML5 Boilerplate plus Twitter Bootstrap’s excellent CSS and JavaScript plugins. A WordPress developer’s dream in a tidy package.

This short video series introduces basic steps for installing and customizing the Roots Themes to suit your needs. By basic, I do mean basic. (Advanced users — you’ve been warned. Flee now. I’ll try to cook up something for you later.)

What these videos will cover:

  1. Downloading and installing the Roots Theme (very basic)
  2. Loading dummy content for theme development (from the WordPress theme unit test)
  3. Creating dropdown menu items (requires the creation of custom links)
  4. Creating a custom page template (introduces inc/roots-config.php)
  5. Creating a custom page loop
  6. Customizing the CSS by adding custom styles to app.css (introduces inc/roots-actions.php)

These videos are more-or-less stand-alone. Choose the topic relevant to your needs and jump in.

One more disclaimer: Production quality is a little rough in spots. Rushed to get these out for my university students. My apologies.

1. Download and Install the Roots Theme

Roots WordPress Theme – Download and Install from David Cochran on Vimeo.

2. Need Dummy Content? Here’s How

WordPress Dummy Content from the Theme Unit Test from David Cochran on Vimeo.

3. Create Dropdown Menu Items

Roots Theme Customization – Dropdown Menu Items from David Cochran on Vimeo.

4. Create a Custom Page Template

Roots Theme Customization – Create a Custom Page Template from David Cochran on Vimeo.

5. Create a Custom Page Loop

Roots Theme Customization – Create a Custom Page Loop from David Cochran on Vimeo.

6. Add your Custom CSS

Roots Theme Customization – Customizing the CSS from David Cochran on Vimeo.

Don’t miss the full Roots Theme series

This is the first installment of a longer series I’m developing on Roots Theme customization.

Additional topics include:

  • Use your custom page template for a static front page
  • Reposition the Navbar
  • More topics in the works …

If you’d like an introduction to Twitter Bootstrap …

Twitter Bootstrap 101 by David Cochran at webdesign.tutsplus.comAgain this is another basic introduction, but if that’s what you’re after, I’ve got a Twitter Bootstrap video tutorial series underway at Webdesign.tutsplus.com.

Build a Faster HTML5 App with Backbone.js, Zepto.js and Trigger.io

This post from Trigger.io shares a strategy for creating Android and iOS apps from a single HTML5 codebase.

The post walks through:

  • including your JavaScript files
  • using Backbone.js to present a responsive interface
  • using the HTML5 boilerplate to reduce inconsistencies across platforms

Read it here: How to build fast HTML5 mobile apps using backbone.js, zepto.js and trigger.io – Cross Platform Dev Blog

CoffeeScript: A Roundup for Beginners

CoffeeScript Logo

CoffeeScript brings new elegance and efficiency to the writing of JavaScript. It helpfully enforces JavaScript best practices. And it compiles into highly performant JSLint compliant code. The golden rule of CoffeeScript is: “It’s just JavaScript”.

Home Base

CoffeeScript.org

Introductory Overviews

Perspectives on CoffeeScript

CoffeeScript Basics: Introductory Articles and Tuts

CoffeeScripter’s Toolkit

  • js2Coffee.org — quickly convert JavaScript to CoffeeScript, and vice versa
  • CoffeeScript Cookbook — online recipes — “CoffeeScript recipes for the community by the community.”

CoffeeScript Books

What is this list missing?

This is a live list. Please post additional recommendations below!

Related Posts

CoffeeScript Intro Video by Sam Stephenson of 37signals

Sam Stephenson, of 37signals and Prototype.js, gives a 45-minute introductory walk through CoffeeScript, it’s uses and benefits, at the Future of Web Apps London, 2011.

Telling Screenshots from the Presentation

Check out these CoffeeScript / JavaScript side-by-side comparisons. The screenshots are not high resolution, but you can get the idea. When possible, I’ve included where these appeared in the presentation.

CoffeeScript Switch Statement (25:03 – 25:50)

Better JS with CoffeeScript Screenshot

Classes and Inheritance — CoffeeScript (29:34)

Better JS with CoffeeScript Screenshot

Comparable inheritance code in JavaScript!

Better JS with CoffeeScript Screenshot

Comprehensions (27:20 – 27:50)

in CoffeeScript

comparable code in JavaScript
Better JS with CoffeeScript Screenshot

Destructuring: Person, Name Split in CoffeeScript (37:30 – 38:20)

Better JS with CoffeeScript Screenshot

Multiline Strings in CoffeeScript (39:23)

Better JS with CoffeeScript Screenshot

Notes from the Presentation

Random Highlights

  • “The golden rule of CoffeeScript is: ‘It’s just JavaScript.'” (12:57-13:22)
  • “All of the crap” (extraneous braces and semicolons) “just fades away.” (13:30-13:40)
  • “JavaScript gives you so many ways to shoot yourself in the foot, but there is a golden path…. and CoffeeScript forces you to use it.” (13:40-14:50)
  • “I see what I’m actually doing. Code looks clearer.”  (21:00 – 22:44)
  • Compiles to code that is optimized for performance, without reliance upon libraries (27:50-59)
  • “Completely lowers the barrier to writing fast, good code.” (28:00 – 28:16)

How CoffeeScript Enforces JavaScript’s Good Parts

For those familiar with Douglas Crockford’s JavaScript: The Good Parts, Stephenson highlights how CoffeeScript pushes you in that direction:

  1. It’s private by default. Each file compiles into a self-executing closure. No leaking of global variables. (14:50 – 16:00)
  2. No more “var” keyword. Enforces lexical scope. (16:00 – 17:06)
  3. Strict comparisons. No more “==” vs. “===” confusion. CoffeeScript’s “is” keyword is always “===”. (17:07 – 18:05)
  4. Runs anywhere. JSLint compliant. (18:06 – 18:40)

10 Best Features of CoffeeScript

Beginning at 18:40, Stephenson walks through 10 of his favorite features of CoffeeScript, with lots of practical coding examples.

Here is a brief summary of his 10 points:

  1. Functions syntax (18:40 – 20:35) — greatly simplified, with much less typing
  2. Significant white space (20:36 – 22:44) — indentation and line breaks replace braces, semicolons. Stephenson: “I see what I’m actually doing. Code looks clearer.”
  3. Bare objects syntax (22:45 – 24:25) — makes for much greater coding efficiency
  4. Everything’s an expression (24:36 – 25:50) — “Everything has a value.”
  5. Comprehensions (25:51 – 28:19) — each, map, select made simple — and compiles to fast, good code
  6. Classes and Inheritance (28:20 – 31:24) — “CoffeeScript makes it incredibly simple and terse to write classes.”
  7. Bound functions (31:25 – 34:39) — the fat arrow => binds a function definition to its current scope, and can also be used to define instance methods
  8. Conditionals (34:40 – 37:10) — greatly simplifies the writing of conditionals
    • allows you to put a conditional at the end of an expression
    • introduces the “unless” keyword
    • introduces the existential operator : “?” at the end of a line checks to see if a value is undefined or null
    • also the soak operator
  9. Destructuring Assignment (37:11 – 38:06) — a proposal for the next version of JavaScript, already available in CoffeeScript
  10. String Syntax (38:07 – 39:39) —
    • does not require string concatenation
    • enables writing of multi-line strings (with indentation) between triple-quotes

How to Use CoffeeScript

Stephenson ends with a few notes regarding ways to incorporate CoffeeScript into your development workflow. (39:40 – 43:34)

  • CoffeeScript.org includes a tool that shows you exactly how a line of CoffeeScript compiles to JS
  • Compiling via command line
  • Compiling on the fly
  • Rails 3.1 Sprockets — automatically compiles CoffeeScript on the fly
    • 37signals currently uses this to use CoffeeScript everywhere
  • Node.js – Stitch project

Related Posts

Comparing Scripts in jQuery and JavaScript: A Comparison by Jeffrey Way

In a recent post, From jQuery to JavaScript: A Reference, Jeffrey Way gives an excellent run-down of how to get scripty things done in three idioms: jQuery, current JavaScript, and legacy JavaScript.

It’s an outstanding read.

Item number one gives a great introduction to JavaScript’s new Selectors API, which approximates jQuery for its ability to query the DOM in CSS-selector style.

So for instance, compare these three ways of doing things:

Selecting Elements

jQuery

$('#container');

JavaScript

var container = document.querySelector('#container');

Legacy JavaScript

var container = document.getElementById('container');

Or consider this:

Add, Remove, and Toggle Classes

jQuery

$('#box').addClass('wrap');
$('#box').removeClass('wrap');
$('#box').toggleClass('wrap');

JavaScript

var container = document.querySelector('#box');
container.classList.add('wrap');
container.classList.remove('wrap');
container.classList.toggle('wrap');

Legacy JavaScript

var box = document.getElementById('box'),
 
    hasClass = function (el, cl) {
        var regex = new RegExp('(?:s|^)' + cl + '(?:s|$)');
        return !!el.className.match(regex);
    },
 
    addClass = function (el, cl) {
        el.className += ' ' + cl;
    },
 
    removeClass = function (el, cl) {
        var regex = new RegExp('(?:s|^)' + cl + '(?:s|$)');
        el.className = el.className.replace(regex, ' ');
    },
 
    toggleClass = function (el, cl) {
        hasClass(el, cl) ? removeClass(el, cl) : addClass(el, cl);
 
    };
 
addClass(box, 'drago');
removeClass(box, 'drago');
toggleClass(box, 'drago'); // if the element does not have a class of 'drago', add one.

Credit: These examples are from the post, From jQuery to JavaScript: A Reference, by Jeffrey Way.

Which is better? — or Which is better When?

As Way points out, the question is not necessarily “Which is better?” but “Which is better when?” JavaScript’s new Selector API goes a long way toward making vanilla JavaScript nearly as easy to work with as jQuery. In cases where we can get things done without loading the jQuery library, our sites will travel lighter and perform a bit snappier.

They take-away: The jQuery library is fantastic when you need it, but in each case, we should pause to ask: “Do I really need jQuery in this case? — Or can I get it done in straight JavaScript?”

Links

Current Favorite WordPress Plugins December 2012

Don’t miss our curated page of best WordPress plugins.

Here are a few of our current favorites. The list is not exhaustive, but it’s a nice little collection of solid recommendations.

Current Favorite Plugins

  • Google Analytics for WordPress by Yoast

    “Uses the asynchronous Google Analytics tracking code, the fastest and most reliable tracking code Google Analytics offers.”

  • WordPress SEO by Yoast

    “Improve your WordPress SEO: Write better content and have a fully optimized WordPress site using the WordPress SEO plugin by Yoast.”

  • Jetpack by WordPress.com

    Social sharing, email subscriptions, stats, spell-check, URL-shortener, Twitter feed widget, easy video embeds, and more.

  • Search Light

    Find-As-You-Type dropdown extension for the standard WordPress search

  • WP-DBManager

    optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database

  • Hyper Cache

    a well reviewed cache plugin specifically for shared hosting

  • Page Links To

    allows you to make a WordPress page or post link to a URL of your choosing, instead of its WordPress page or post URL

  • Redirection

    Manage 301 redirections, keep track of 404 errors, and generally tidy up any loose ends your site may have. This is particularly useful if you are migrating pages from an old website, or are changing the directory of your WordPress installation.

  • Disable Trackbacks

    “Globally disables trackbacks to cut down on spam. Very, very few people legitimately use trackbacks and spammers love them, so it’s worthy tradeoff.”

Don’t miss our curated page of best WordPress plugins.

Have great plugins to recommend? Use the comments below to suggest new additions to our list.

Smoother Loading Typekit Fonts: A nice approach by Joni Korpi

For lovers of Typekit webfonts: If you want to guarantee that your pages load for all users without glitches, you’ll want to use Typekit’s asynchronous loading script. Advantage: pages will load fine for all users even in the event of a font network outage. Disadvantage: you’ll notice a flash of unstyled text (FOUT).

Joni Korpi, designer of the Golden Grid System and the Frameless grid system, has proposed a nice solution, which involves creative use of:

  • loading classes provided by Typekit
  • CSS3 transitions for fade-in
  • a base64 animated image to indicate that fonts are loading

As you’ll notice while perusing his blog, it provides a nice effect. I’m contemplating this method.

Read Joni’s post about this method

How does it strike you?

Related Links

Backbone.js: A Roundup for Beginners

Backbone.js LogoBringing MVC architecture to the creation of Web applications, Backbone.js helps you manage complexity while keep your coding practices clean, including maintaining a neat separation of content from presentation. Backbone.js plays well with other libraries, giving developers freedom to follow their own preferences for DOM scripting — whether with jQuery, Dojo, Prototype, etc.

Developed by Jeremy Ashkenas, creator of CoffeeScript, Backbone.js has quickly built an active and helpful community of developers. If you’d like to start learning more about it, here are some excellent places to start.

Home Base

Backbone.js lives here

Ecosystem

Resource Roundups

Leading Competitors

Related Posts

A Case for Sproutcore over Backbone.js for Web Apps

Sproutcore Logo

@mfied makes an interesting case for utilizing Sproutcore for web app development.

Read the Post

Via Building interactive web apps with SproutCore | Minified:

Currently, Backbone gets a lot of the attention, and rightly so, it’s a great framework. In this post though, I want to demonstrate a use case where I believe SproutCore 2 excels — building interactive web apps.

Developing in SproutCore takes away the need to update and re-render views, and the focus shifts entirely to managing and updating the client side data model.

Go read the post

Related