Getting to The Loop - London Wordpress Meetup  July 28th
Upcoming SlideShare
Loading in...5
×
 

Getting to The Loop - London Wordpress Meetup July 28th

on

  • 2,574 views

This is a slightly modified version of the talk I gave at the London Wordpress meetup. ...

This is a slightly modified version of the talk I gave at the London Wordpress meetup.

I'm putting it up here a) for people who were taking notes last night and b) to shame me into putting a polished version up here for people who couldn't make it.

thanks for @folletto for providing the graphics that split up the endless code snippets.

Statistics

Views

Total Views
2,574
Views on SlideShare
1,717
Embed Views
857

Actions

Likes
2
Downloads
9
Comments
0

5 Embeds 857

http://sltaylor.co.uk 825
http://sltaylor.localhost 26
http://www.linkedin.com 3
http://translate.googleusercontent.com 2
http://www.zhuaxia.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Getting to The Loop - London Wordpress Meetup  July 28th Getting to The Loop - London Wordpress Meetup July 28th Presentation Transcript

  • Getting to The Loopworking with themes is commonplace, buthow WP gets there is still seen as magic.it doesn’t need to be that hard. Here’s how itgets there...
  • Load Plugins DB Template The Loop
  • Load in files for a bootstrap phaseset up Pluginsturn the request URL into a DB querychoose a Templatestart The Loop
  • Load
  • important files for this step:• index.php• blog-header.php• wp-load.php• wp-settings.php
  • index.php<?php/** * Front to the WordPress application. This file doesntdo anything, but loads * wp-blog-header.php which does and tells WordPress toload the theme. */define(WP_USE_THEMES, true);/** Loads the WordPress Environment and Template */require(./wp-blog-header.php);?>
  • blog-header.php<?php/** * Loads the WordPress environment and template. */ require_once( dirname(__FILE__) . /wp-load.php ); wp(); require_once( ABSPATH . WPINC . /template-loader.php );}?>
  • wp-load.php<?php/** Define ABSPATH as this files directory */define( ABSPATH, dirname(__FILE__) . / );if ( file_exists( ABSPATH . wp-config.php) ) { require_once( ABSPATH . wp-config.php );} else { wp_die("There doesnt seem to be a wp-config.php file.I need this before we can get started. );}?>
  • wp-load.php<?php/** Define ABSPATH as this files directory */define( ABSPATH, dirname(__FILE__) . / );if ( file_exists( ABSPATH . wp-config.php) ) { require_once( ABSPATH . wp-config.php );} else { wp_die("There doesnt seem to be a wp-config.php file.I need this before we can get started. );}?>
  • wp-config.php<?php///** The name of the database for WordPress */define(DB_NAME, database_name_here);/** MySQL database username */define(DB_USER, username_here);/** MySQL database password */define(DB_PASSWORD, password_here);/** Sets up WordPress vars and included files. */require_once(ABSPATH . wp-settings.php);
  • wp-config.php<?php///** The name of the database for WordPress */define(DB_NAME, database_name_here);/** MySQL database username */define(DB_USER, username_here);/** MySQL database password */define(DB_PASSWORD, password_here);/** Sets up WordPress vars and included files. */require_once(ABSPATH . wp-settings.php);
  • wp-settings.php<?php// Load early WordPress files.require( ABSPATH . WPINC . /compat.php );require( ABSPATH . WPINC . /functions.php );require( ABSPATH . WPINC . /class-wp.php );require( ABSPATH . WPINC . /class-wp-error.php );require( ABSPATH . WPINC . /plugin.php );// Load most of WordPress.require( ABSPATH . WPINC . /class-wp-ajax-response.php );require( ABSPATH . WPINC . /formatting.php );require( ABSPATH . WPINC . /query.php );
  • wp-settings.php<?php// Make taxonomies and posts available to plugins and themes.create_initial_taxonomies();create_initial_post_types();// Load active plugins.foreach ( wp_get_active_and_valid_plugins() as $plugin ) { include_once( $plugin );}do_action( plugins_loaded );do_action( setup_theme );do_action( after_setup_theme );do_action( wp_loaded );?>
  • Plugins
  • plugins, hooks, actionsadd_action( ‘hook’, ‘function’) do_action(‘admin_notices’) apply_filteradd_filter(‘hook’, $template) (‘template_redirect’)
  • loading plugins
  • hello_dolly_example.php// Fetch a random song lyric and add it to the pagefunction hello_dolly() { $chosen = hello_dolly_get_lyric(); echo "<p id=dolly>$chosen</p>";}// Now we set that function up to execute when theadmin_notices action is calledadd_action( admin_notices, hello_dolly );
  • loading plugins
  • DB
  • turn the request URL into a DB query• from - http://mysite.com/category/something• to - WP_Query(category=‘something’)
  • class-wp.php<?phpclass WP { function main($query_args = ) { $this->init(); $this->parse_request($query_args); $this->send_headers(); $this->query_posts(); $this->handle_404(); $this->register_globals(); do_action_ref_array(wp, array(&$this)); }
  • class-wp.php<?phpclass WP { function main($query_args = ) { $this->init(); $this->parse_request($query_args); $this->send_headers(); $this->query_posts(); $this->handle_404(); $this->register_globals(); do_action_ref_array(wp, array(&$this)); }
  • Template
  • blog-header.php<?php/** * Loads the WordPress environment and template. */ require_once( dirname(__FILE__) . /wp-load.php ); wp(); require_once( ABSPATH . WPINC . /template-loader.php );}?>
  • blog-header.php<?php/** * Loads the WordPress environment and template. */ require_once( dirname(__FILE__) . /wp-load.php ); wp(); require_once( ABSPATH . WPINC . /template-loader.php );}?>
  • template-loader.php<?php// (abridged version)if ( is_single() && $template = get_single_template() ) : elseif ( is_page() && $template = get_page_template() ) : elseif ( is_category() && $template = get_category_template() ) : elseif ( is_tag() && $template = get_tag_template() ) : elseif ( is_author() && $template = get_author_template() ) : elseif ( is_date() && $template = get_date_template() ) : elseif ( is_archive() && $template = get_archive_template() ) :
  • The Loop
  • Start The Loop• we now have our template, chosen inside template-loader.php• we now have our query results from wp() in wp-blog-header.php• now hand these over to The Loop - thanks Keith!
  • Phew! Thank you!c@headshift.com@mrchrisadams