130 likes | 154 Views
WordPress Architecture. Core files – PHP MySQL database Configured by the installation script wp-content directory themes subdirectory: layout plugins subdirectory: extensions uploads subdirectory: uploaded files Version updates relatively painless. Presentation: Choose a Theme.
E N D
WordPress Architecture • Core files – PHP • MySQL database • Configured by the installation script • wp-content directory • themes subdirectory: layout • plugins subdirectory: extensions • uploads subdirectory: uploaded files • Version updates relatively painless
Presentation: Choose a Theme Current Theme Default Themes 100’s available Administrator’s View
Theme Architecture • Set of files installed in a subdirectory of wp-content/themes • Typical theme set includes • style.css and required images • PHP template files defining parts of the pages • header, footer, sidebar, comments • PHP template files defining entire pages • Runtime selection based on template hierarchy • Can also set page template when creating the page Administrator’s View
Template Architecture • Not Smarty • But does serve to separate content generation from presentation • Dozens of predefined tags • Simple example: get_header() • Called “tags,” but most are functions • Example: list categories • list_cats() – 18 positional parameters • wp_list_cats() – arguments as name/value pairs Administrator’s View
Editing Templates Administrator’s View
Example template: page.php <?php get_header(); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2> <?php the_content(__('Read the rest of this page »')); ?> <?php wp_link_pages(); ?> <?php edit_post_link(__('Edit'), '<p>', '</p>'); ?> <?php endwhile; endif; ?> <?php get_sidebar(); ?> <?php get_footer(); ?> Administrator’s View
get_header • get_sidebar • the_title • the_content • edit_post_link • get_footer
Digression: The Loop <?php if (have_posts()) : while (have_posts()) : the_post(); ?> …. <?php endwhile; endif; ?> • Applies to “WordPress Pages” as well as “pages” that display “WordPress Posts” • Many tags to control what happens inside • is_category() • is_page() • More conditional tags Administrator’s View
Extensibility: Plugins Administrator’s View
Sample Plugin: Hello, Dolly $lyrics = explode("\n", $lyrics); $chosen = wptexturize( $lyrics[ mt_rand(0, count($lyrics) ) ] ); function hello_dolly() { global $chosen; echo "<p id='dolly'>$chosen</p>"; } add_action('admin_footer', 'hello_dolly'); function dolly_css() { echo "<style type='text/css'> #dolly { … style attributes … } </style>"; } add_action('admin_head', 'dolly_css'); Administrator’s View
Before activation After activation “Hello, Dolly” in action Administrator’s View
Customizing Your SiteOther Options Quotes Links Calendar Book List RSS Feeds