一个WordPress主题至少要包括下面两个文件:
/* Theme Name: Twenty Fifteen Theme URI: https://wordpress.org/themes/twentyfifteen/ Author: the WordPress team Author URI: https://wordpress.org/ Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, straightforward typography is readable on a wide variety of screen sizes, and suitable for multiple languages. We designed it using a mobile-first approach, meaning your content takes center-stage, regardless of whether your visitors arrive by smartphone, tablet, laptop, or desktop computer. Version: 1.2 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: black, blue, gray, pink, purple, white, yellow, dark, light, two-columns, left-sidebar, fixed-layout, responsive-layout, accessibility-ready, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready Text Domain: twentyfifteen This theme, like WordPress, is licensed under the GPL. Use it to make something cool, have fun, and share what you've learned with others. */
<?php /** * The Header for our theme. * */ ?><!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>" /> <meta name="viewport" content="width=device-width" /> <title><?php wp_title( '|', true, 'right' ); ?></title> <!-- HTML5 SHIV for IE --><!-- If using Modernizr you can remove this script! --> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> <header class="site-header"> <h1> <a href="<?php echo home_url(); ?>"> <img src="<?php bloginfo('template_directory'); ?>/images/ logo.jpg" alt=" "> </a> </h1> </header>
comments.php用来显示文章的评论。
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>"> <div><label class="screen-reader-text" for="s">Search for:</label> <input type="text" value="" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form>
包含模板文件可以通过PHP的include()来完成,但WordPress准备了一些模板函数来调用这些模板文件:
<?php get_header(); ?> <div class="container"> <div class="search"> <?php get_search_form(); ?> </div> <div class="main"> <?php // do stuff ?> <?php comments_template(); ?> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?>
get_sidebar('secondary');会调用模板文件 sidebar-secondary.php。