Pro Yearly is on sale from $80 to $50! »

So, you want to build a theme?

So, you want to build a theme?

This is a 10,000 ft view of the basics for WordPress theme development. Thomas McMahon and myself walk you through some of these things.

453a9f8bb6755a35227babb4bb4863bb?s=128

John Heimkes IV

April 26, 2014
Tweet

Transcript

  1. So, you want to build a WordPress theme?

  2. None
  3. What We’ll Cover at a high level... Theme Files The

    Loop Custom Queries Where to Find Help
  4. Theme Files

  5. Get the Template Map at http://bit.ly/WP-Map Doesn’t have to be

    complicated!
  6. Minimum Files index.php & style.css

  7. <?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main"> <?php

    if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; ?> </main><!-- #main --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?> index.php
  8. /* Theme Name: WordCamp Minneapolis 2013 Theme URI: http://exmaple.com Author:

    John & Thomas Author URI: http://example.com Description: Our first theme for WordCamp MPLS 2014 Version: 1.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/ gpl-2.0.html */ style.css
  9. Optional Files • page.php • 404.php • archive.php • search.php

    • single.php • header.php • footer.php • sidebar.php • 404.php • functions.php
  10. functions.php • Brains of Your Theme • Add Features &

    Functionality • Enqueue Styles & Scripts • Set Thumbnail Sizes • Custom Post Types & Taxonomies • Setup Menus • Setup Sidebars • Custom PHP
  11. The Loop

  12. The Loop • the_title • the_content • the_post_thumbnail • the_date

    • the_author Displays post information that is stored in the database.
  13. The Loop Example <?php if (have_posts()) : ?> <?php while

    (have_posts()) : the_post(); ?> <h2><?php the_title() ;?></h2> <?php the_post_thumbnail(); ?> <?php the_content(); ?> <p>by <?php the_author(); ?> on <?php the_date(); ?></p> <?php endwhile; ?> <?php endif; ?>
  14. Custom Queries

  15. Basic Query <?php $args = array( 'posts_type' => 'post' );

    $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; } } wp_reset_postdata(); ?>
  16. Query + Author <?php $args = array( 'posts_type' => 'post',

    'author' => 123 ); $the_query = new WP_Query( $args ); ! if ( $the_query->have_posts() ) {...} wp_reset_postdata(); ?>
  17. Query + Category <?php $args = array( 'posts_type' => 'post',

    'author' => 123, 'cat' => 4 ); $the_query = new WP_Query( $args ); ! if ( $the_query->have_posts() ) {...} wp_reset_postdata(); ?>
  18. Query + Limit <?php $args = array( 'posts_type' => 'post',

    'author' => 123, 'cat' => 4, 'posts_per_page' => 12 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) {...} wp_reset_postdata(); ?>
  19. Custom Query Options • The Codex has many more options.

    • https://codex.wordpress.org/Class_Reference/ WP_Query
  20. Help!

  21. The Codex • Official WordPress Documentation • Example Code •

    Optional and Require Attributes • https://codex.wordpress.org/
  22. WordPress Stack Exchange • Good Support Forum • Quality Answers

    • Focused on Development • http://wordpress.stackexchange.com/
  23. Google • Google, as always, is a great resource. •

    Lots of blog posts and tutorials. • http://www.google.com
  24. What We Covered Theme Files The Loop Custom Queries Where

    to Find Help What it takes. How to pull in post data. How to customize the data pulled. To the rescue!
  25. Questions? John Heimkes IV @johnheimkes Thomas McMahon @TwisterMc via tekartist.org