building a simple theme framework - · pdf file• common wordpress functionality (menus,...

27
Building a Simple Theme Framework by: Joe Casabona Saturday, October 20, 12

Upload: vantram

Post on 01-Feb-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Building a Simple Theme Framework

by: Joe Casabona

Saturday, October 20, 12

Page 2: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Who am I?

• Native of NYS

• Yankee Fan

• WordPress Developer

• Computer Nerd

• Star Wars Nerd

• Author of Building WordPress Themes from Scratch

Saturday, October 20, 12

Page 3: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Software Reuse• Some General Principles & Tips

Saturday, October 20, 12

Page 4: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Software Reuse

• What is it? Creating code that can be used across several projects. Using existing software to create new software.

• Why is it Important?

• It saves time

• It’s easier to test

• It allows you to focus on more advanced parts of a project.

Saturday, October 20, 12

Page 5: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Principles of Reuse• Design Your Code

• Layout functions, classes, page templates before hand!

• Generalize Where Possible

• Recognize when you’re reusing code snippets

• Document & Test Thoroughly!

• Testing will ensure your code works before implementing it 5, 10, or 20 times

Saturday, October 20, 12

Page 6: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Define Your Needs

• We all have different needs!

• I’ll talk about mine. Keep yours in mind.

• Evaluate Your Process

• Review Your Code

• What do you do over and over?

• Look for the same code across recent projects!

Saturday, October 20, 12

Page 7: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Define Your Needs (my needs)

• Plugable CSS

• Constants for Theme & Image URLS

• Common WordPress functionality (menus, sidebars, CPTs, etc.)

• Most Common theme templates (header, footer, page, index)

• Common Folders

• Lightweight

Saturday, October 20, 12

Page 8: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Now What?

• You know what you needs. Now what?

• Before you code, see what’s out there!

• Can a plugin or other theme fulfill your needs?

• Is there already some theme you use as a starting point?

Saturday, October 20, 12

Page 11: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Building the Framework• What to do, what to do...

Saturday, October 20, 12

Page 12: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Designing Your Code

• I noticed I was doing a couple of things over and over

• Copy K2

• Rip out stuff I didn't use

• Replace it with my standard template

• Modify

• Eventually, I would just copy the last theme I created

• I took my common components and created my framework

Saturday, October 20, 12

Page 13: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Ex: Post Attachmentsfunction jlc_prnt_attachements($pid){$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $pid );

$attachments = get_posts( $args );

if ($attachments) {foreach ( $attachments as $post ) {

setup_postdata($post); the_attachment_link($post->ID, false, false, true); }}

}

Saturday, October 20, 12

Page 14: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Necessary Files

• Style.css

• Functions.php

• Index.php

• That’s it! WordPress will fill in the blanks with only these.

Saturday, October 20, 12

Page 15: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Recommended Files• All Necessary files

• header.php & footer.php

• page.php

• single.php

• A Custom Post Type generator/template

• A theme options generator/template

• search.php

• archive.php

• sidebar.php

Saturday, October 20, 12

Page 16: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

My CSS

• Single Sheet

• Compressed normalize.css

• Some base styles

• Standard HTML5 Elements

• Basic Navigation CSS

• Mobile first approach

• Basic Media Queries

• Any common classes and IE Fixes

Saturday, October 20, 12

Page 17: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

My Functions

• Constants to use throughout the whole theme:define( 'TEMPPATH', get_bloginfo('stylesheet_directory'));

define( 'IMAGES', TEMPPATH. "/images");

• Calls to include:

• Nav Menus

• Sidebars (2)

• Custom functions I use across multiple themes (like attachments function from earlier)

Saturday, October 20, 12

Page 18: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Using the Framework• How and When

Saturday, October 20, 12

Page 19: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

• As a Child Theme:

• Cleaner

• Easier to update

• Can overwrite any page

• As a Boilerplate:

• One off jobs you don’t plan on updating

• Largely customized jobs where you want to reuse only parts of the framework.

2 Ways to Use Framework

Saturday, October 20, 12

Page 20: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

As a Child Theme

• Allows you to create themes that will automatically get updated when you update your framework

• Bug Fixes

• Additional Functionality

• General Theme Updates

• Overwrites

• No need to hack together/delete. Import and overwrite!

Saturday, October 20, 12

Page 21: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

As a Boilerplate

• Did this for a while!

• This project started to serve as a simple boilerplate for me

• Use for one-off projects

• Projects you won't have control over after initial launch

• Projects that will be deeply different structurally

Saturday, October 20, 12

Page 22: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Which Should I Use?

• Cliche Answer: It Depends!

• As with most things in our field, there is no be-all-end-all answer.

• Consider the project at hand and make the call there.

• Practically speaking, a child theme of your framework will likely work most of the time.

Saturday, October 20, 12

Page 23: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Some Tips

• Test it thoroughly

• You will use this a lot, so make sure things work as expected across multiple browsers

• Improve and update it

• As you grow as a developer, your needs will change. Make sure your framework changes with you.

Saturday, October 20, 12

Page 24: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Some Tips (cont)

• Don't get complacent

• Do let your growth stagnate because you're using a framework.

• Stay up on new features, best practices, etc.

• Let others try it out

• See how other people use it and get feedback.

Saturday, October 20, 12

Page 25: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

if there is time...<? Show some code! ?>

Saturday, October 20, 12

Page 26: Building a Simple Theme Framework -   · PDF file• Common WordPress functionality (menus, sidebars, CPTs, etc.) ... • A Custom Post Type generator/template

Thank You!Any Questions?

Site: casabona.orgSlides: casabona.org/wcphilly/Twitter: @jcasabona

Saturday, October 20, 12