WordPress

Introduction

This page and its sub-pages were primarily created as a quick reference for myself. The results are thus somewhat subjective and selective. I welcome suggestions and corrections.

The material is in various states of presentability. I’m trying to move everything to a place where it is readily usable by others.

Terminology

  • Event Driven Programming – Executes when something happens, can be similar to MVC, but oftentimes lacks a clear and separate controller.
  • Model View Controller (MVC) Programming – A style of programming in which the model (data) is separated from the view (presentation) by the controller. This model is not used by WordPress.
  • Enqueued Files – Files that are included when WordPress loads, generally these are JavaScript and CSS files registered in functions.php.
  • Custom Fields
  • Hooks – Places within WordPress’ code that allow for insertion of one’s own code.
    • Actions – “Actions are events in the WordPress page lifecycle when certain things have occurred – certain resources are loaded, certain facilities are available, and, depending on how early the action has occurred, some things have yet to load.” (McFarlin)
    • Filters – “Filters are functions that WordPress passes data through during certain points of the page lifecycle. They are primarily responsible for intercepting, managing, and returning data before rendering it to the browser or saving data from the browser to the database.” (McFarlin)
  • Navigation
  • Page Lifecycle – This is where events are triggered.
  • Files & Templates Hierarchy
  • Template Files
  • Page Templates
  • Template Tags – WordPress functions that can be used within a template to retrieve and display data. Preferred method of pulling in content.
    • Conditional Tags – When certain conditions are true/false you can have different behavior occur in a template file.
  • Template Partials – Parts of a template included in other template files (header, sidebar, and footer, etc.).
  • Pagination
  • Post Type – Determines what sort of content is shown by the templated file.
    • Default Post Types
      • Post (‘post’) – display by single, single-post, category, tag, taxonomy, archive, author, date, search, home, and index.
      • Page (‘page’) – page, $custom, front-page, search, index
      • Attachment (‘attachment’) – MIME_type, attachment, single-attachment, single, index
      • Revision (‘revision’)
      • Navigation Menu (‘nav_menu_item’)
  • Custom Post Types – Should be created via plugin, not in theme.
    • Following are setup to display custom posts: single-{post-type}.php, archive-{post-type}.php, search.php, index.php
    • Can be displayed on any page using loops.
  • Scripts
  • Taxonomy – A grouping together of similar things, the taxonomy being the sum of all those groups.
    • Default Taxonomies: categories, tags, post formats
    • Terms – Items within taxonomy.
      • Create programmatically using wp_insert_term()
  • The Loop
  • Sidebars
  • Widgets
  • Feature Images & Post Thumbnails
  • Functions.php
  • If template uses body_class() function, WordPress will add classes in the body tag for post type class name, page ID, and page template used.
    • ex.: <body class=”page page-id-6 page-template-default”>
    • Specialized page templates use page-template-default
    • In custom templates it looks like:
      <body class=”page page-id-6 page-template page-template-my-custom-post-php”>
  • When creating new files, use the next file up in the template hierarchy as a copy and base to launch off of.

Media

  • Images: adjustments, sizing, presentation, labels, captions
  • Audio: clips, levels, labels, descriptions
  • Video: clips, levels, labels, descriptions
  • Galleries: presentation, page setup, ordering, labels, descriptions

Variables

  • $wpdb->prefix = Used to retrieve the prefix for WordPress DB tables as this may change from DB to DB.

Parameters

  • ‘rewrite’ => array(‘slug’ => ‘products’) – Used to rewrite custom post identifiers if they have been namespaced, inside of create_posttype().

Interacting

  • Use filter or action hooks.
  • Use custom template tags.

Code Snippets

Bibliography & Further Reading

Leave a Reply