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.
CNIC Information System with Pakdata Cf In Pakistan
Getting to The Loop - London Wordpress Meetup July 28th
1. Getting to The Loop
working with themes is commonplace, but
how WP gets there is still seen as magic.
it doesn’t need to be that hard. Here’s how it
gets there...
5. important files for this
step:
• index.php
• blog-header.php
• wp-load.php
• wp-settings.php
6. index.php
<?php
/**
* Front to the WordPress application. This file doesn't
do anything, but loads
* wp-blog-header.php which does and tells WordPress to
load the theme.
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
?>
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 doesn't seem to be a wp-config.php file.
I need this before we can get started. );
}
?>
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 doesn't seem to be a wp-config.php file.
I need this before we can get started. );
}
?>
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. 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');
17. hello_dolly_example.php
// Fetch a random song lyric and add it to the page
function hello_dolly() {
$chosen = hello_dolly_get_lyric();
echo "<p id='dolly'>$chosen</p>";
}
// Now we set that function up to execute when the
admin_notices action is called
add_action( 'admin_notices', 'hello_dolly' );
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!