Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

CHAPTER 4 • WordPress Theme Essentials 93


<?php get_sidebar(); ?>



<?php get_footer(); ?>


Basically, it’s a simple template file with the error message in itself. This will be shown when a
nonexistent page is accessed.


The search.php template is closely related to index.php. In fact, if you don’t have a search
template, index.php will be used. You can either copy index.php and edit it accordingly or just
add some tags for when search results are displayed. For this theme, you’ll go with the latter,
adding this to index.php, just after the section#content-container:


<?php
// If it is a search result
if ( is_search() ) :
?>




This has a simple conditional check to find out if the page in question is a search result, and if
it is, the search query is outputted in an h1 tag. Sometimes you don’t need more than that.


Oh, and don’t forget to put a screenshot.png file depicting your theme in the theme folder. The
file should be 300 x 225 pixels and will be used in the Themes section of the WordPress admin
interface. Make it look nice, but more importantly, make it look like the theme — otherwise,
you’ll confuse your users, and you won’t get to use your theme in the WordPress.org themes
directory should you want to.


FEATURES WITH FUNCTIONS.PHP


The primary toolbox of theme designers is called functions.php. This file is loaded with the
theme and lets you do cool stuff, almost plugin-like. This is where you activate features such
as custom backgrounds and headers, featured images, and menus. You’ll revisit functions.php
later in this chapter for a more in-depth look, and you’ll revisit it again several times in this
book. But first, take a look at the really short and simple functions.php used in your Simple
Blog theme:


<?php
// Set content width for the theme
if (! isset( $content_width ) )
$content_width = 500;

Free download pdf