Theming 101

Theming 101

An introduction to WordPress theming for complete beginners. Talk given at WordCamp Winnipeg on June 1, 2013.

Matt Wiebe

June 01, 2013

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

64 slides
  1. Theming 101 ★ What is a theme? ★ How do

    I make a theme? ★ How do I make an awesome theme?
  2. What is a Theme? A WordPress Theme is a collection

    of files that work together to produce a graphical interface with an underlying unifying design for a weblog. These files are called template files. — http://codex.wordpress.org/Themes
  3. What is a Theme? ★ A directory/folder of files in

    wp-content/themes ★ Two necessary files ★ style.css ★ index.php ★ the rest make sense as you go
  4. style.css /* Theme Name: Twenty Thirteen Theme URI: http://wordpress.org/themes/twentythirteen Author:

    the WordPress team Author URI: http://wordpress.org/ Description: Much longer than this ;) Version: 0.1 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: black, brown, ETC Text Domain: twentythirteen */
  5. style.css /* Theme Name: Twenty Thirteen Theme URI: http://wordpress.org/themes/twentythirteen Author:

    the WordPress team Author URI: http://wordpress.org/ Description: Much longer than this ;) Version: 0.1 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: black, brown, ETC Text Domain: twentythirteen */
  6. style.css /* Theme Name: Your Awesome Theme Name */ /*

    Actual CSS for your theme goes below */
  7. index.php <?php get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content"

    role="main"> <?php if ( have_posts() ) : ?> <?php /* The loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php twentythirteen_paging_nav(); ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
  8. index.php <?php get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content"

    role="main"> <?php if ( have_posts() ) : ?> <?php /* The loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php twentythirteen_paging_nav(); ?> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
  9. The Loop <?php while ( have_posts() ) : the_post(); ?>

    <?php // print out a post's HTML ?> <?php endwhile; ?>
  10. The Loop <?php while ( have_posts() ) : the_post(); ?>

    <article> <h1><?php the_title(); ?></h1> <div><?php the_content(); ?></div> </article> <?php endwhile; ?>
  11. index.php <?php get_header(); // loads header.php ?> <?php while (

    have_posts() ) : the_post(); ?> <article> <h1><?php the_title(); ?></h1> <div><?php the_content(); ?></div> </article> <?php endwhile; ?> <?php get_footer(); // loads footer.php ?>
  12. header.php <!DOCTYPE html> <html> <head> <meta charset="<?php bloginfo( 'charset' );

    ?>" /> <link href="<?php bloginfo( 'stylesheet_url' ) ?>" rel="stylesheet" /> <?php wp_head(); ?> </head> <body>
  13. style.css /* Theme Name: WordCamp Winnipeg */ body { background-color:

    #333; color: #ddd; font-family: sans-serif; margin: 2em; line-height: 1.6; }
  14. Template Hierarchy ★ Everything falls back to index.php eventually ★

    Mostly easy to follow ★ single.php → Single post ★ page.php → Static page ★ category.php → Category archive ★ http://codex.wordpress.org/Template_Hierarchy
  15. functions.php ★ Tiny, theme-specific plugin ★ Should only have things

    that are theme-specific ★ Telling WordPress what features you support and how you support them
  16. index.php <?php get_header(); // loads header.php ?> <?php while (

    have_posts() ) : the_post(); ?> <h1><?php the_title(); ?></h1> <article><?php the_content(); ?></article> <?php endwhile; ?> <?php dynamic_sidebar( 'sidebar-1' ); ?> <?php get_footer(); // loads footer.php ?>
  17. Learn From the Best ★ _s → A starter theme

    from Automattic ★ Embedded best practices
  18. Learn From the Best ★ _s → A starter theme

    from Automattic ★ Embedded best practices ★ http://underscores.me/
  19. Learn From the Best ★ Make a child theme ★

    Build on a solid base without starting from scratch ★ The Twenty * themes are good for this
  20. Learn From the Best ★ Learn how some of the

    intro stuff I just taught you was lacking or just plain bad!

More Decks by Matt Wiebe

Other Decks in Technology