3. So why custom?
“Premium” themes are often difficult
or bloated with scripts.
Meeting the needs of the client specifically.
Custom WP themes & Admin
Matt Adams @mattada
4. Assumptions.
We need to assume a few things for today.
1. You have used wordpress and are familiar
with basic themes, options and settings.
2. You have some level of HTML & CSS
experience, and are comfortable with code.
Custom WP themes & Admin
Matt Adams @mattada
9. style.css
/*
Theme Name: Wordcamp theme 1
Theme URI: http://www.yoursiteURL.com
Description: A short intro about this project
Author: matt adams
Author URI: http://factor1studios.com
Version: 1.0
*/
10. The Loop.
some wp magic
Custom WP themes & Admin
Matt Adams @mattada
11. Introducing The Loop
The Loop is PHP code used by WordPress to
display posts. Using The Loop, WordPress
processes each post to be displayed on the
current page, and formats it according to how
it matches specified criteria within The Loop
tags. Any HTML or PHP code in the Loop will
be processed on each post.
Custom WP themes & Admin
Matt Adams @mattada
12. The Loop looks like this:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php else : ?>
<?php endif ?>
<!-- Do post and page content stuff -->
<!-- Do stuff after the posts -->
<!-- Not found, lets inform the visitor of that. -->
13. The Loop with some content
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content();?>
<?php endwhile; ?>
!
<?php else : ?>
<?php endif ?>
<h2>Not Found</h2>
19. So now what?
Moving from HTML to WP
Custom WP themes & Admin
Matt Adams @mattada
20. Identify the key sections
Header.php
Logo & Nav
Page Body
Sidebar
Recent
post 1
Sidebar.php
Recent
post 2
page.php
Footer
Footer.php
Custom WP themes & Admin
Matt Adams @mattada
27. Introducing the functions.php
The functions file behaves like a
WordPress Plugin, adding features and
functionality to a WordPress site. You can
use it to call functions, both PHP and
built-in WordPress, and to define your
own functions.
Custom WP themes & Admin
Matt Adams @mattada
28. Creating the functions.php
<?php
// One PHP tag at the top for all your functions
!
!
register_sidebar( array(
'name' => __( 'Main Sidebar' ),
'id' => 'sidebar',
'description' => __( 'The primary widget area right side'),
'before_widget' => '<div id="%1$s" class=“widget">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
!
!
!
// Close the PHP tag after ALL your functions are done!
?>
30. Introducing WP menus
As of wordpress 3.0 and newer, we can
quickly and easily add menu support and
easy administration of the navigation to
any theme.
Custom WP themes & Admin
Matt Adams @mattada
31. Register the menu on functions.php
// Register WP3 theme menus
register_nav_menus( array(
'primary' => __( 'Primary Navigation' ),
'utility' => __( 'Utility Links' ),
'socialmedia' => __( 'Social Media Links')
) );
We can register as many as we want!
Each will be editable in WP menus
33. Lets build a home page
Logo & Nav
Hero Image
Call to
action 1
Header.php
Featured
Image
Call to
action 2
Footer
Custom WP themes & Admin
Matt Adams @mattada
Call to
action 3
3 on page
Elements
Footer.php
34. New page template - page-home.php
<?php
/*Template Name: Home Page */
get_header(); ?>
/*Template Name:__________*/
gets us this menu
in the page edit screen
<?php get_footer(); ?>
35. New page template - page-home.php
<?php
/*Template Name: Home Page */
get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="hero row">
<div class="medium-12 columns">
</div>
<?php the_post_thumbnail('hero'); ?>
</div><!— Close the hero row —>
!
<div class="home_action row">
<div class="medium-4 columns">
<a href="">
<img src="http://placehold.it/250x250">
</a>
</div>
</div><!— Close the home_action row —>
!
<?php endwhile; endif; ?>
<?php get_footer(); ?>
36. The result:
But where did the hero image go?
Custom WP themes & Admin
Matt Adams @mattada
37. Adding featured images to our functions.php
<?php
!
// Add thumbnail support
if ( function_exists('add_theme_support') )
add_theme_support('post-thumbnails');
?>
Set the custom crop size
<?php add_image_size( $name, $width, $height, $crop ); ?>
Full code
True: Crops to center
False: Reduces to max size
<?php
!
// Add thumbnail support
if ( function_exists('add_theme_support') )
add_theme_support('post-thumbnails');
add_image_size( 'hero', 1000, 400, true ); // Homepage Hero Image
?>
39. What if i go from:
add_image_size( 'hero', 1000, 400, true ); // Homepage Hero Image
to something bigger:
add_image_size( 'hero', 1000, 500, true ); // Homepage Hero Image
2 options.
a. Remove the image and re-upload
b. Use a plugin to regenerate the thumbnails
http://wordpress.org/plugins/regenerate-thumbnails/
Custom WP themes & Admin
Matt Adams @mattada
41. Managing our home page call to actions
Call to
action 1
Call to
action 2
Call to
action 3
3 on page
Elements
Advanced Custom Fields plugin
http://wordpress.org/plugins/advanced-custom-fields/
By Elliot Condon
Custom WP themes & Admin
Matt Adams @mattada
42. Creating our ACF group and elements
Custom WP themes & Admin
Matt Adams @mattada
43. Creating our ACF group and elements
ACF post / page options
Custom WP themes & Admin
Matt Adams @mattada
44. Creating our ACF group and elements
Adding the first custom field
Custom WP themes & Admin
Matt Adams @mattada
45. The resulting custom field
Editing the home page using the page-home.php
Custom WP themes & Admin
Matt Adams @mattada
46. Getting the custom fields on the template
<?php the_field('image_test'); ?>
The field name assigned when we created the field
Using a conditional statement
<?php
if(get_field('field_name'))
{
echo '<p>' . get_field('field_name') . '</p>';
}
?>'); ?>
47. For our home call to action
we need an image URL.
<div class="home_action row">
<div class="medium-4 columns">
<a href="">
</a>
<img src="<?php the_field('item1_image'); ?>">
</div>
Results:
48. Additional content
opportunities
via functions.php
Custom post types like Portfolios, Staff,
Testimonials, Case Studies, Products, etc.
Registering new javascript libraries, removing
admin panels or pages.
Custom WP themes & Admin
Matt Adams @mattada
49. Combo these up
for the win!
Register a Custom post type for a portfolio.
Then add in custom fields for details
Now use the archive-posttype.php to display.
Custom WP themes & Admin
Matt Adams @mattada
52. codex.wordpress.org
All things official code base & support
digwp.com
Articles and Books on WP
generatewp.com
Tools for functions, post types, loops, etc.
build.codepoet.com
Tutorials, interviews and best practices
Custom WP themes & Admin
Matt Adams @mattada