wordpress theme development: part 2

20
WordPress Theme Development Part II

Upload: josh-lee

Post on 22-Jul-2015

35 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: WordPress Theme Development: Part 2

WordPress Theme

Development

Part II

Page 2: WordPress Theme Development: Part 2

Who am i?

● Owner of QC Creative, a local digital

marketing and web development agency

● Web developer for over 10 years

● Since 2010, 90% of projects have been in

WordPress

● @joshleecreates

Page 3: WordPress Theme Development: Part 2

Quick Review

Page 4: WordPress Theme Development: Part 2

PHP Basics

PHP allows logic

operations with

variables:$x = 1;

$y = 2;

$z = $x + $y;

And with functions:

echo( ‘Hello, World’ );

$post_title

= get_post_title();

Page 5: WordPress Theme Development: Part 2

PHP Basics

Conditionals:$x = true;

if( $x == true ) {

echo( ‘x is true’);

}

x is true

Loops:$x = 0;

while( $x <= 10 ) {

echo( ‘x is: ‘ . $x

);

}

x is: 0

x is: 1

x is: 2

...

Page 6: WordPress Theme Development: Part 2

Template Tags

Template tags allow you to use a small PHP

snippet to inject values from your WordPress

database into a pagethe_title();

the_content();

the_excerpt();

the_post_thumbnail();

Page 7: WordPress Theme Development: Part 2

Output or retrieve data

`the_` tags output

content directly into

the page:

<h1>

<?php the_title(); ?>

</h1>

`get_` tags retrieve

values which can be

manipulated first:<h1>

<?php

$title = get_the_title();

echo( $title );

?>

</h1>

Page 8: WordPress Theme Development: Part 2

Conditional Tags

`is_` template tags return a boolean

(true/false) value, useful for conditional

statements:is_single();

is_page();

is_category();

is_page( ‘about-us’ );

Page 9: WordPress Theme Development: Part 2

The Template Hierarchy

WordPress determines what kind of view is

being requested, and combines the content

for that view with a specific template (PHP

file) from the theme.

The “Template Hierarchy” determines which

PHP template is used for which views.

Page 10: WordPress Theme Development: Part 2

The Template Hierarchy

http://codex.wordpress.org/Template_Hierarchy

Page 11: WordPress Theme Development: Part 2

Anatomy of a Request

How does WordPress build a page?

Page 12: WordPress Theme Development: Part 2

How does WordPress build a page?

1. User requests page

2. WP initialized

3. Plugins initialized

4. Theme initialized

5. Query type

identified

6. Template

identified

And finally…

The page is rendered

by processing the

chosen template

together with actions

and filters

Page 13: WordPress Theme Development: Part 2

“Theme Initialized” = functions.php

● functions.php is the first part of

the theme to get run

● It is always run after plugins are

initialized

Page 14: WordPress Theme Development: Part 2

Common Functions

● Enqueue scripts and styles

● Modify queries for specific pages

● Modify plugin or WP core behavior (actions)

● Modify plugin or WP core output (filters)

● Declare theme support

● Include other PHP libraries

Page 15: WordPress Theme Development: Part 2

What is Theme Support?

Page 16: WordPress Theme Development: Part 2

What is theme support?

● add_theme_support()

● Tells WP which features your theme can

support

● E.g.: featured images, HTML5 markup, etc.

● http://codex.wordpress.org/Function_Refe

rence/add_theme_support

Page 17: WordPress Theme Development: Part 2

Hooks, Actions, & Filters

Doing it the WordPress way

Page 18: WordPress Theme Development: Part 2

What are Hooks?

A hook is an anchor associated with a specific

event within WordPress

E.g.:

● A page is requested

● A query is run

● the_content() is output for a post or page

● A user logs in

Page 19: WordPress Theme Development: Part 2

What are actions? Filters?

Actions & Filters are functions that you

define, and attach to a specific hook.

Page 20: WordPress Theme Development: Part 2

Which means…

We can tell WordPress:

● Whenever doing X, first do Y

● E.g.:o Whenever loading the blog homepage, first add my

custom post type to the query