writing a wordpress theme - highedweb 2013 #wrk2

23
WORDPRESS THEMES A H IGHE DWEB 201 3 WO R KSHOP #WRK2 #HEWEB13

Upload: curtiss-grymala

Post on 15-May-2015

6.489 views

Category:

Technology


0 download

DESCRIPTION

A basic introduction to creating a new WordPress theme

TRANSCRIPT

Page 1: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

WORDPR

ESS THEMES

A H

I GH

ED

WE

B 2

01

3 W

OR

KS

HO

P

#WRK2

#HEWEB13

Page 2: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

#WRK2

#HEWEB13

Page 3: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

DIFFERENT

TYPE

S OF

THEMES

F RA

ME

WO

RK

S,

P AR

EN

TS

AN

D C

HI L

D T

HE

ME

S

#WRK2

#HEWEB13

Page 4: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

FRAMEWORKS, PARENTS & CHILDREN

• Parent Theme• A base theme that sets up functionality• Can be extended• Must be written to allow overrides

• Child Theme• Extends a parent theme• Can carry over or override elements from parent• Cannot be extended without plugins

• Framework• Not a full theme; more of a plugin for a theme• Allows creation of parent and child themes with shared functionality

http://justintadlock.com/archives/2010/08/16/frameworks-parent-child-and-grandchild-themes

#WRK2

#HEWEB13

Page 5: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

EXAMPLES

Hybrid Core is a framework. - http://themehybrid.com/hybrid-core

• No theme structure• Full package goes inside parent theme

Genesis “Framework” is a parent theme - http://www.studiopress.com/features •Has a theme structure• Can be used on its own•Does not go inside of another theme

TwentyTwelve is a parent theme - http://wordpress.org/extend/themes/twentytwelve • Although it has less of a framework built in, same concept as Genesis

“Education” is a child theme - http://my.studiopress.com/themes/education/ • Cannot be used without Genesis (parent theme) installed

#WRK2

#HEWEB13

Page 6: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

START

ING A

THEME

BA

SI C

EL E

ME

NT

S O

F AL L T

HE

ME

S

#WRK2

#HEWEB13

Page 7: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

REQUIRED FILES

CSS Stylesheet (style.css)*• Implements the CSS for the theme• Not included by default• enqueue it in functions.php or • use <link href=“<?php bloginfo( ‘stylesheet_uri’ ) ?>”/> in <head>

• Provides base information about the theme• Theme name, URI, version, license, etc. (http://

codex.wordpress.org/Theme_Development#Theme_Stylesheet)

Index (index.php)• Implements the structure of the theme• Can be split out into multiple files• Acts as fallback for all pages**

* - style.css is the only file required in a child theme; all others fallback to parent theme

** - the Template Hierarchy governs which files are used for each page; index is the final fallback

#WRK2

#HEWEB13

Page 8: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

TYPICAL THEME FILES

Theme Functions (functions.php)• Central location for function, variable, constant defintions used in theme• Included automatically by theme engine before after_setup_theme action

Default Sidebar (sidebar.php)•Outputs default sidebar (get_sidebar())

Default WordPress Loop (loop.php)• Not included automatically by theme• Used to separate “the loop”*** from other structure

Comments Template (comments.php)• List of comments and comment form; use comments_template() to include

Search (search.php)• Search results template; automatically used on search results page

#WRK2

#HEWEB13

Page 9: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

MOAR THEME FILES

Automatic Template Files (page.php, 404.php, single.php)• Used automatically based on type of page being shown; •Overrides index.php (see the Template Hierarchy)

Miscellaneous Files (sidebar-[slug].php, etc.)• Include with the get_template_part( ‘sidebar’, ‘[slug]’ ) function• Sidebar, header and footer files can be included with:• get_sidebar( ‘[slug]’ )• get_header( ‘[slug]’ )• get_footer( ‘[slug]’ )

Header and Footer (header.php, footer.php)• Not included automatically • Call with get_header() & get_footer()

#WRK2

#HEWEB13

Page 10: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

TEMPL

ATE H

IERARCHY

HO

W W

OR

DP

RE

SS

DE

CI D

ES

WH

AT

FI L

E T

O U

SE

#WRK2

#HEWEB13

Page 11: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

THE WORDPRESS TEMPLATE HIERARCHY

WordPress automatically searches for appropriate theme template file

#WRK2

#HEWEB13

Page 12: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

THE LO

OP

TH

E M

AI N

CO

NT

EN

T A

RE

A O

F YO

UR

TH

EM

E

Page 13: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

WHAT IS “THE LOOP”?

The Loop outputs the main content area• Loops through all matching content objects

if ( have_posts() ) : while ( have_posts() ) : the_post();

// Output all of your content

endwhile; endif;

have_posts() and the_post()•Global methods of main query object ($wp_query)• have_posts() generates array of “post” objects• the_post() sets global variables related to current post object

#WRK2

#HEWEB13

Page 14: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

OTHER “LOOP” FUNCTIONS

Inside the loop, various functions are available

• the_title() – echoes the title of the current post

• the_content() – echoes the body of the current post

• the_post_thumbnail() – echoes the “featured image” for current post

#WRK2

#HEWEB13

Page 15: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

MOAR LOOP TIPS

If you need to use the same query loop more than once:

• Use rewind_posts() to reset the loop to be used again

You can start your own loop with a custom query:

$myquery = new WP_Query( ‘[query parameters go here]’ );

if ( $myquery->have_posts() ) : while ( $myquery->have_posts() ) : $myquery->the_post();

// Your custom loop stuff hereendwhile; endif;

• Don’t alter the global $wp_query or use query_posts() unless you know what you’re doing

• Use get_posts() or create your own loop, instead

Page 16: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

CREATIN

G THE T

HEME

TU

RN

I NG

A D

ES

I GN

IN

TO

A W

OR

DP

RE

SS

TH

EM

E

Page 17: Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Page 18: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

STEP 1: DESIGN

• Identify goals

• Wireframe and design

• Layout priorities

• Final template design

• Initial HTML layout

Page 19: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

STEP 2: DIVIDE AND CONQUER

• Identify layout elements

• Identify content elements

• Identify visual decoration

• Determine common elements

• Identify alternative layouts

Page 20: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

STEP 3: DEVELOP

• Begin developing basic layout

• Separate layout elements from content elements

• Replace content elements with placeholders

• Create layout structure and style

• Develop content containers (body, widgets, footer, header, etc.)

• Develop custom functionality

Page 21: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

JUST

DO IT!

L ET

’ S B

UI L

D A

TH

EM

E

Page 22: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

LET’S DO THIS THING

Examine Theme Design – http://2013.highedweb.org/

Identify Theme Elements

Create required files

style.css - http://j.mp/153SWWv

index.php – wp_head() & wp_footer() - http://j.mp/153Tagt

functions.php (not required, but recommended)

#WRK2

#HEWEB13

Page 23: Writing a WordPress Theme - HighEdWeb 2013 #WRK2

QUESTIONS? COMMENTS?

Twitter: @cgrymala

Website(s): http://umw.edu/ (Multi-Network Setup)

http://ten-321.com/

http://svn.ten-321.com/ (SVN Repo)

http://wphighed.org/ (WP resources for Higher Ed)

Email: [email protected]

[email protected]

SpeakerRate: http://spkr8.com/s/10608

http://about.me/cgrymala

#WRK2

#HEWEB13