How WordPress themes actually work

How WordPress themes actually work? You don’t need to be a code ninja to use one, but a little knowledge might help you make the most of your theme.  It also helps when the inevitable snags throw up something you’re not expecting.

A WordPress Theme is a collection of files that work together to produce a graphical interface with an underlying unifying design for a weblog.  I.e. a consistent look and feel and way your site works.

These files are called template files. A Theme modifies the way the site is displayed, without modifying the underlying software. Themes may include customised template files, image files as well as any necessary code files:

  • image files (*.jpg,*.gif)
  • style sheets (*.css)
  • code files (*.php).

WordPress themes are made up of a folder of template files. These files control a specific piece of your theme. Parts of your site that remain static no matter what page you’re on are controlled by header, sidebar and footer files. You can modify these files so they detect what page you are on and serve different content accordingly.

  • header.php
  • Global file that displays headers and navigation. Also contains HTML code.
  • The Loop
  • The display of contents of the main area of your site is controlled by individual WordPress theme template files using what’s called “the loop”.
  • sidebar.php
  • Sidebar display is controlled in this file. Multiple sidebars can be set up in functions.php, and contents of sidebar widgets are set up from the WordPress wp-admin panel.
  • footer.php
  • Contains instructions for global footer and closes HTML tags.

index.php – home

The index file controls what the homepage of your WordPress theme looks like. By default, it is a loop that queries and then displays the most recent blog posts, with a link at the bottom to view previous posts.

single.php – individual posts

The display of individual posts in your WordPress theme is controlled by a little file called single.php. It contains a loop that queries just one post and displays it.

You can specify if you want sidebars (and which you want), if you want it to look different than the other pages on the site.

page.php – individual pages

Page.php controls what pages look like. You can choose to eliminate sidebars or other elements, add other unique elements for pages alone.

WordPress also allows you to create different page templates within your WordPress theme for different types of pages. To create a page template, simply copy page.php, rename it to whatever you want, then add this code to the top:

<?php

/*

Template Name: Pagename

*/

?>

archive.php, category.php, tag.php – archives

You can control the look and feel of different archives using template files also. If there is no archive file, the archives will look like index.php; however you can create an archive.php to override that. If you create a file called category.php, it will override archive.php for categories only. If you create a tag.php, you can override it for tag archives only.

 

The Loop

 

The loop is the most powerful part of your WordPress theme. It starts with a query which determines which posts or pages to grab and ends with a PHP statement. Everything in between is up to you. You can specify the output of titles, post content, metadata, custom fields and commenting all within the loop and each element is output for each post or page until the query is done. You can set up multiple loops and queries on a single page; for example: on a single.php you could have the loop showing the entire content of a single post, with a loop outputting just titles and thumbnails for related posts below it.

  • Query post or page
  • Start Loop
  • the_title (outputs the title of the post)
  • the_excerpt (outputs the post excerpt)
  • the_content (outputs the full post content)
  • the_category (outputs the post categories)
  • the_author (outputs the post author)
  • the_date (outputs the post date)
  • other tags (there is a variety of other tags you can use in the loop)
  • endwhile;
  • Exit the loop

Background files of a WordPress theme

 

In order for a WordPress theme to work, it needs a few essential background files that can be modified to your needs.

comments.php

This controls the output of comments, which can be included in the loop if you desire comments on your theme. Comments.php can be overridden by plugins.

functions.php

Functions.php allow you to put your own custom PHP code in order to modify core elements of your theme. This can be multiple sidebars, the number of characters in the excerpt or add custom admin panel options for wp-admin.

style.css

This is the main CSS stylesheet for your theme.

The WordPress Theme Directory is the official site for WordPress Themes which have been checked and inspected, and are free for downloading. It enables you to search by type and style, and offers a demonstration of the page view elements of the Theme.  To get the best themes for very little investment, a third party theme site such as themeforest.net is worth a look.  Most individuals and small businesses will only require a professionally-designed theme, which is less than EUR 100, along with free plugins.

To get the best themes for very little investment, a third party theme site such as themeforest.net is worth a look.  Most individuals and small businesses will only require a professionally-designed theme, which is less than EUR 100, along with free plugins.

Get started on your WordPress.org website straight-away with Cloudnames. Simply register your new or existing domain name, install WordPress and start designing!

Recommended Posts

Leave a Comment

Start typing and press Enter to search

Beginners guide to WordPress web design - Cloudnames blog