Intro to Parent and Child themes
WordPress supports a concept known as "theme templates" which is most commonly referred to as "parent" and "child" themes. Any theme can declare a different theme as its "parent" or "template" by adding an additional line to the header comment of style.css:
* Template: twentytwelve
The above example would make the current theme a "child" of the TwentyTwelve theme, inherently making TwentyTwelve the parent. Note that nothing needs to change about TwentyTwelve for this to work.
Now, anytime WordPress needs a template file it will look first to the current active theme, then it will fall back to TwentyTwelve and try to load the file from there. If the file doesn't exist in TwentyTwelve, WordPress will look for the next file in the template hierarchy inside the current theme, falling back to TwentyTwelve again if not found, and so on.
You can learn more about Child and Parent Themes from the WordPress Developer Handbook.
Also read about the template tag get_template_part()
if you're unfamiliar.
Alumni Theme
The Alumni theme is currently the main web/wp-content/themes/cornell
theme. Everything that the Alumni site needs to render its various templates are included in this theme.
Giving Theme
The Giving theme, web/wp-content/themes/cornell-giving
, is a child of the web/wp-content/themes/cornell
theme. This theme includes a few custom templates and overrides for the main Cornell theme.
Important Custom Templates
In addition to the standard template hierarchy, the Cornell theme makes use of a custom "base" file that serves as a "wrapper template" (learn more here and here) for all of the other templates. Helper functionality for this wrapper behavior is provided in web/wp-content/themes/cornell/lib/wrapper.php
- Base (base.php) - Wrapper template for nearly every page request.
- Custom (template-custom.php) - A sample, unused template.
- Landing (template-landing.php) - The primary template used for all types of landing pages. Leverages flexible, repeatable fields.
- Landing News (template-landing-news.php) - The News landing template. Used as the primary news archive. Gets content output from
web/wp-content/themes/cornell/templates/content-landing-news.php
- List (template-list.php) - Used for showing navigable list sections.
- Program (template-program.php) - Custom template for the Program page.
How to identify template parts
The fastest and easiest way to determine which template partials are being loaded for a particular page is to leverage the Query Monitor plugin. bash wp plugin install query-monitor --activate
This plugin adds an additional menu to the admin bar on the front-end. Clicking it will expose a menu full of options. Clicking on the Template item will scroll you to the footer where the plugin lists the hierarchy WP used to determine which template to reference as well as all of the partials that were loaded from that template.
Template Functionality
This theme comes with a /lib/
directory loaded with extra functionality. These files provide custom template tags, filter functions, and baseline functionality for the theme.
Extras (modifications for third-parties)
The extras.php file is primarily used to filter various site behavior. This file includes the google analytics tracking script, modifies the list of available widgets, adjusts archive titles, and things of that nature. In short, if there is a layout-based change that needs to occur globally, it's probably happening via filter and within this file.
Query Helpers
There are a number of different query helper functions that have been written and stored in this globally accessible file. The purpose of these is to limit how often a particular query gets rewritten. This practice makes it far simpler to find and optimize the different queries that may power different parts of the site.
Other Helpers
Have a look at setup.php
, titles.php
, wrapper.php
, and helpers.php
. Each of them contain a number of useful functions for easily powering shared functionality across the themes.
Custom Fields
Much of the content that is output to the templates come from custom fields. These fields are managed using one of two tools: cmb2
and carbon-fields
. Everything could be done by cmb2
alone but carbon-fields
was added to support repeatable nested field groups. Therefore, carbon-fields
was selected for powering the flexible fields leveraged by template-landing.php
(and a couple of other places).
How to add/modify custom fields
For the most part, custom fields and settings are controlled in web/plugins/cornell-content
. In this plugin you will find /config/
and inside there you will find carbon-fields
and fields
. Each of these directories contain the configuration definitions for all of the different metaboxes and fields used by all post types and custom templates.
Read each project's documentation to learn more about how they work and what they can do: - CMB2 Documentation - Carbon Fields Documentation