Upload
alexander-oneal
View
221
Download
3
Embed Size (px)
Citation preview
WordPress ArchitectureWordPress Architecture
►Core files – PHPCore files – PHP►MySQL database MySQL database
Configured by the installation scriptConfigured by the installation script
►wp-content directorywp-content directory themes subdirectory: layout themes subdirectory: layout plugins subdirectory: extensionsplugins subdirectory: extensions uploads subdirectory: uploaded filesuploads subdirectory: uploaded files
►Version updates relatively painlessVersion updates relatively painless
Presentation: Choose a Presentation: Choose a ThemeTheme
Current ThemeCurrent Theme
Default ThemesDefault Themes
100’s available100’s available
Administrator’s ViewAdministrator’s View
Theme ArchitectureTheme Architecture
►Set of files installed in a subdirectory Set of files installed in a subdirectory of wp-content/themesof wp-content/themes
►Typical theme set includesTypical theme set includes style.css and required imagesstyle.css and required images PHP template files defining parts of the pagesPHP template files defining parts of the pages
►header, footer, sidebar, commentsheader, footer, sidebar, comments
PHP template files defining entire pagesPHP template files defining entire pages►Runtime selection based on Runtime selection based on template hierarchytemplate hierarchy►Can also set page template when creating the pageCan also set page template when creating the page
Administrator’s ViewAdministrator’s View
Template ArchitectureTemplate Architecture
►Not Smarty Not Smarty But does serve to separate content But does serve to separate content
generation from presentationgeneration from presentation
►Dozens of predefined tagsDozens of predefined tags Simple example: get_header()Simple example: get_header()
►Called “tags,” but most are functionsCalled “tags,” but most are functions Example: list categoriesExample: list categories
►list_cats() – 18 positional parameterslist_cats() – 18 positional parameters►wp_list_cats() – arguments as name/value pairswp_list_cats() – arguments as name/value pairs
Administrator’s ViewAdministrator’s View
Editing TemplatesEditing Templates
Administrator’s ViewAdministrator’s View
Example template: page.phpExample template: page.php
<?php get_header(); ?><?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?<h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>></h2>
<?php the_content(__('Read the rest of this page <?php the_content(__('Read the rest of this page »')); ?>»')); ?>
<?php wp_link_pages(); ?><?php wp_link_pages(); ?>
<?php edit_post_link(__('Edit'), '<p>', '</p>'); ?><?php edit_post_link(__('Edit'), '<p>', '</p>'); ?>
<?php endwhile; endif; ?><?php endwhile; endif; ?>
<?php get_sidebar(); ?><?php get_sidebar(); ?>
<?php get_footer(); ?><?php get_footer(); ?>
Administrator’s ViewAdministrator’s View
►get_headerget_header►get_sidebarget_sidebar►the_titlethe_title►the_contentthe_content►edit_post_liedit_post_li
nknk►get_footerget_footer
Digression: The LoopDigression: The Loop
Administrator’s ViewAdministrator’s View
<?php if (have_posts()) : while (have_posts()) : the_post(); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?>
……..
<?php endwhile; endif; ?><?php endwhile; endif; ?>
►Applies to “WordPress Pages” as well as Applies to “WordPress Pages” as well as “pages” that display “WordPress Posts”“pages” that display “WordPress Posts”
►Many tags to control what happens insideMany tags to control what happens inside is_category()is_category() is_page()is_page() More More conditional tagsconditional tags
Extensibility: PluginsExtensibility: Plugins
Administrator’s ViewAdministrator’s View
Sample Plugin: Hello, DollySample Plugin: Hello, Dolly
Administrator’s ViewAdministrator’s View
$lyrics = explode("\n", $lyrics);$lyrics = explode("\n", $lyrics);
$chosen = wptexturize( $lyrics[ mt_rand(0, count($lyrics) ) ] );$chosen = wptexturize( $lyrics[ mt_rand(0, count($lyrics) ) ] );
function hello_dolly() {function hello_dolly() {
global $chosen;global $chosen;
echo "<p id='dolly'>$chosen</p>";echo "<p id='dolly'>$chosen</p>";
}}
add_action('admin_footer', 'hello_dolly');add_action('admin_footer', 'hello_dolly');
function dolly_css() {function dolly_css() {
echo "<style type='text/css'>echo "<style type='text/css'>
#dolly { … style attributes … }#dolly { … style attributes … }
</style>";</style>";
}}
add_action('admin_head', 'dolly_css');add_action('admin_head', 'dolly_css');
““Hello, Dolly” in actionHello, Dolly” in action► Before activationBefore activation
► After activationAfter activation
Administrator’s ViewAdministrator’s View
Customizing Your SiteCustomizing Your SiteOther OptionsOther Options
Links
Quotes
Calendar
RSS Feeds Book List