Getting to The Loop - London Wordpress Meetup July 28th

2,463 views
2,327 views

Published on

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.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,463
On SlideShare
0
From Embeds
0
Number of Embeds
883
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Getting to The Loop - London Wordpress Meetup July 28th

  1. 1. 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...
  2. 2. Load Plugins DB Template The Loop
  3. 3. Load in files for a bootstrap phaseset up Pluginsturn the request URL into a DB querychoose a Templatestart The Loop
  4. 4. Load
  5. 5. important files for this step:• index.php• blog-header.php• wp-load.php• wp-settings.php
  6. 6. 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);?>
  7. 7. 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 );}?>
  8. 8. 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. );}?>
  9. 9. 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. );}?>
  10. 10. 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);
  11. 11. 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);
  12. 12. 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 );
  13. 13. 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 );?>
  14. 14. Plugins
  15. 15. plugins, hooks, actionsadd_action( ‘hook’, ‘function’) do_action(‘admin_notices’) apply_filteradd_filter(‘hook’, $template) (‘template_redirect’)
  16. 16. loading plugins
  17. 17. 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 );
  18. 18. loading plugins
  19. 19. DB
  20. 20. turn the request URL into a DB query• from - http://mysite.com/category/something• to - WP_Query(category=‘something’)
  21. 21. 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)); }
  22. 22. 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)); }
  23. 23. Template
  24. 24. 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 );}?>
  25. 25. 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 );}?>
  26. 26. 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() ) :
  27. 27. The Loop
  28. 28. 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!
  29. 29. Phew! Thank you!c@headshift.com@mrchrisadams

×