WordPress Theme Development Note

Template tags

The WordPress standard template tags for inserting snippets of html/php, such as get_header, get_footer, get_sidebar etc reside in the file wp-includes/general_template.php. They are incredibly simple functions, with the names (‘header’, ‘footer’…) hardcoded within the functions. Also if you pass in a string as a parameter then that is appended to the name separated by a ‘-‘, and both the extended name and shortend name are searched for:

  • xxxxx-string_param.php
  • xxxxx.php

Full list of template tags provided with WordPress can be found at

From my perspective the tags fall into three categories:

  • Retrieval of data from the wp database
  • Provision of standard functionality
  • Insertion of HTML/PHP, usually, but not necessarily with some form of Dynamic content.

Those that are concerned with data retrieval fall into two categories:

  • Those retrieving data concerning the current post or page. These Template Tags have to reside within the WordPress data retrieval loop.
  • None Post/Page related data, such as Site URL, User, Logged-in status, List of Posts, Pages, Categories etc.

Customize API

The customize API is the mechanism whereby Theme developers can provide site Administrators with the ability to easily customize their site, for example by providing facilities to change background images, logos, text fonts etc. The Customize API is fully object based, and centres around four object classes:

  • Panels – Most outwardly UI container. A panel basically contains a set of sections (As a principle Themes should not create panels or modify existing panels. (Plugin developers may have a need to extend or modify existing Panels)
  • Section – A UI Container for UI Controls
  • Control – UI Control. Generally any HTML UI control can be accommodated. In addition there are some WordPress customize controls already available for importing images, media files, etc, and for cropping images.
  • Setting – Each control must be associated with a setting object. The Setting object is in effect the data object for the UI Class. It is serialized to the database and can be accessed by the various template files using the get_theme_mod(‘settings-id’) function.

Post Formats

These appear to be add on features that posts can have. Not sure why it is called Post Formats. However it looks like:

  • aside
  • gallery
  • quote
  • link
  • image
  • status
  • video
  • audio
  • chat

Post Formats are enabled at the Theme level by including ‘add_theme_support()’ in the functions.php file, eg

add_theme_support( 'post-formats',  array( 'aside', 'gallery', 'quote', 'image', 'video') );

Categories for Pages

The following code included in the theme set_up will enable categories for Page post-types. However this will not affect which template file is used as the template heirarchy does not search categories for page post-types.

		//Add site-page category for post-type 'page';
		if (file_exists (ABSPATH.'/wp-admin/includes/taxonomy.php')) 
			require_once (ABSPATH.'/wp-admin/includes/taxonomy.php'); 

				'cat_name' 				=> 'Site Page',
				'category_description'	=> 'This category identifies thos pages that will use the site-page template',
				'category_nicename' 	=> 'site-page',
				'taxonomy' 				=> 'category'

To implement template filtering with page categories you will need to include something along the lines of the following code. What this code is doing is, for posts for which ‘is_site_page’ returns true, the template file ‘category-site-page.php’ is added into the template search heirarchy.

 * Insert category-site-page template into template search heirarchy.
function q5_category_site_page_template( $templates = '' ) 
    $page = get_queried_object(); 
	if (is_site_page($page))
		if ( ! is_array( $templates ) && ! empty( $templates ) ) 
			$templates = locate_template( array( "category-site-page.php", $templates ), false ); 
		elseif ( empty( $templates ) ) 
			$templates = locate_template( "category-site-page.php", false ); 
			$new_template = locate_template( array( "category-site-page.php" ) ); 
			if ( ! empty( $new_template ) ) 
				array_unshift( $templates, $new_template ); 
    return $templates; 
add_filter('page_template','q5_category_site_page_template' );

General Development Notes

Leave a Reply