Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

John Heimkes IV

April 26, 2014
Tweet

More Decks by John Heimkes IV

Other Decks in Programming

Transcript

  1. What We’ll Cover at a high level... Theme Files The

    Loop Custom Queries Where to Find Help
  2. <?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
  3. /* 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
  4. Optional Files • page.php • 404.php • archive.php • search.php

    • single.php • header.php • footer.php • sidebar.php • 404.php • functions.php
  5. 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
  6. The Loop • the_title • the_content • the_post_thumbnail • the_date

    • the_author Displays post information that is stored in the database.
  7. 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; ?>
  8. 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(); ?>
  9. Query + Author <?php $args = array( 'posts_type' => 'post',

    'author' => 123 ); $the_query = new WP_Query( $args ); ! if ( $the_query->have_posts() ) {...} wp_reset_postdata(); ?>
  10. 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(); ?>
  11. 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(); ?>
  12. Custom Query Options • The Codex has many more options.

    • https://codex.wordpress.org/Class_Reference/ WP_Query
  13. The Codex • Official WordPress Documentation • Example Code •

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

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

    Lots of blog posts and tutorials. • http://www.google.com
  16. 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!