Getting started with WordPress
Remarks#
WordPress is an open source Content Management System (CMS) which is used to build and manage websites. WordPress is the most popular CMS on the internet by a country mile, powering about half of all CMS websites at time of writing and about a quarter of all websites on the internet.
WordPress started life as a platform for blogging but has evolved over the years to be suitable for most types of websites. The interface can be used without coding knowledge making it popular for beginners and developers who want to empower their clients to manage their own website.
Another large factor in the popularity of WordPress is it’s flexibility, mostly due to the core’s plugin and theming systems. The plugin system makes it easy to extend the core functionality without modifying the core code. In a similar manner, the theming system makes it easy to change the website’s layout and aesthetics. There are now thousands of free and premium WordPress plugins and themes available. Many of these are located at the wordpress.org plugin repository and theme repository respectively.
WordPress is developed by it’s own community, but is strongly associated with the company Automattic, which employs many of WordPress’ core developers.
Code
WordPress is built upon the PHP server scripting language and the MySQL querying language. WordPress uses MySQL as a datastore for user content and configuration. The PHP wrangles the content data into a HTML webpage with all the necessary assets.
wordpress.com vs wordpress.org
You can use WordPress by signing up for Automattic’s wordpress.com service and hosting your website on their servers, or you can download the WordPress software from wordpress.org and host your website on a server under your control. The first option is easy but you cannot edit any site code. You can only make changes through the WordPress interface. The second option requires more work but gives you flexibility to do whatever you like with your website code. If you are a StackOverflow user, you probably will be going with the second option.
Open Source
WordPress is open source software meaning it is free to use and anyone can view the source code and contribute to it. Potential contributors can get started by reading the Contribution page of the WordPress codex..
Bugs can be reported by submitting a bug on the WordPress ticket tracker.
Documentation
WordPress is officially documented in the WordPress Codex at WordPress.org. Developers working with WordPress will be particularly interested in the Developer Codex section and Developer Reference section of wordpress.org.
Versions#
Version | Release Date |
---|---|
1.0 | 2004-01-03 |
1.2 | 2004-05-22 |
1.5 | 2005-02-17 |
2.0 | 2005-12-26 |
2.1 | 2007-01-22 |
2.2 | 2007-05-16 |
2.3 | 2007-09-24 |
2.5 | 2008-03-29 |
2.6 | 2008-07-15 |
2.7 | 2008-12-10 |
2.8 | 2009-06-10 |
2.9 | 2009-12-18 |
3.0 | 2010-06-17 |
3.1 | 2011-02-23 |
3.2 | 2011-07-04 |
3.3 | 2011-12-12 |
3.4 | 2012-06-13 |
3.5 | 2012-12-11 |
3.6 | 2013-08-01 |
3.7 | 2013-10-24 |
3.8 | 2013-12-12 |
3.9 | 2014-04-16 |
4.0 | 2014-09-04 |
4.1 | 2014-12-17 |
4.2 | 2015-04-23 |
4.3 | 2015-08-18 |
4.4 | 2015-12-08 |
4.5 | 2016-04-12 |
4.6 | 2016-08-16 |
4.7 | 2016-12-06 |
4.8 | 2017-06-08 |
Introduction to WordPress
WordPress [WP] is an open source Content Management System for building apps, websites, and blogs. WP is written in PHP and uses MySQL as the data store for the user content and configuration. It has a rich ecosystem of plugins and themes and enjoys a vibrant open source community, good documentation, and low barriers to entry. Usability and developer documentation can be found in the WP Codex.
A part of WordPress that makes it different from most other CMS products is its Event Driven Programming. This is a different way of programming and logic representation then the MVC (Model View Controller) architecture which is used by most of the CMS systems. WordPress uses the concepts of Actions and Filters. They form a queue of events that allow plugins and themes to insert, modify or even remove parts of the final web application page and/or parts. A similar concept is JIT or Just-In-Time compiling.
While historically WordPress has been known as a blogging platform, and it may never lose this stigma, the focus of the core WordPress team has clearly changed. With the 2016 State of the Word, by founder Matthew Mullenweg, we can see a clear shift in goals, vision and effort. In 2016, we saw amazing progress when the WordPress core adopted a majority of the very popular REST API plugin. This was clearly an intention of the core team early on when they began a bold effort of building a front-end JavaScript CMS admin panel, that breaks away from the golden standard we have seen for so many years; they called it Calpyso.
WordPress Themes
Mapping URLs to specific templates
To fully grasp WordPress themes, you must understand two primary concepts:
- Permalinks
- The Template Hierarchy
A permalink is a permanent, non-changing URL (or link, to a specific resource. For instance:
- example.com/about-us/ (a Page in WP)
- example.com/services/ (a listing of multiple items, also called an “archive” in WP lingo)
- example.com/services/we-can-do-that-for-you/ (an individual item)
When a user requests a URL, WordPress reverse-engineers the permalink to figure out which template should control its layout. WordPress looks for the various template files that could control this particular piece of content, and ultimately gives preference to the most specific one it finds. This is known as the Template Hierarchy.
Once WP finds the matching view template in the hierarchy, it uses that file to process and render the page.
For example:
index.php
(the default, “catch-all” template) will be overridden by archive.php
(the default template for list-based content), which will in turn be overridden by archive-services.php
(a template file specifically for the archive named “services”).
Here is a great visual reference for the Template Hierarchy
Basic Theme Directory Structure
A simple theme looks something like this:
// Theme CSS
style.css
// Custom functionality for your theme
functions.php
// Partials to include in subsequent theme files
header.php
footer.php
sidebar.php
comments.php
// "Archives", (listing views that contain multiple posts)
archive.php
author.php
date.php
taxonomy.php
tag.php
category.php
// Individual content pages
// Note that home and frontpage templates are not recommended
// and they should be replaced by page templates
singular.php
single.php
page.php
front-page.php
home.php
// Misc. Utility Pages
index.php (a catch-all if nothing else matches)
search.php
attachment.php
image.php
404.php
Example of a “Single” (template for an individual post)
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
What’s happening here? First, it loads header.php
(similar to a PHP include or require), sets up The Loop, displays the_title
and the_content
, then includes comments.php
, sidebar.php
, and footer.php
. The Loop does the heavy lifting, setting up a Post
object, which contains all the information for the currently-viewed content.
Example of an “Archive” (template for a list of multiple posts)
<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>"<?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
First, it includes header.php
, sets up The Loop, and includes sidebar.php
, and footer.php
. But in this case there are multiple posts in the loop, so instead an excerpt is shown with a link to the individual post. next_posts_link
and previous_posts_link
are also included so the archive can paginate results.
Posts, Pages, Custom Post Types, and Custom Fields
Out of the box, WordPress supports two types of content: Posts
and Pages
. Posts are typically used for non-hierarchical content like blog posts. Pages are used for static, standalone content like an About Us page, or a company’s Services page with nested sub-pages underneath.
As of version 3.0, developers can define their own custom post types to extend the functionality of WordPress beyond just the basics. In addition to custom post types, you can also create your own custom fields to attach to your posts/pages/custom post types, allowing you to provide a structured way of adding and accessing metadata within your templates. See: Advanced Custom Fields.