Build Your Own Business Website header image

Introduction to Customizing Thesis 2.1 Using PHP

Difficulty Level -

Filed Under Topics - ,

Listed Under Lesson Subjects - ,

Applies to -

With the advent of Thesis 2 most folks don’t need to muck about with PHP. Most of the typical WordPress coding that people do is easily handled with drag and drop in the Thesis Skin Editor.

However, there are times when DIYers and developers alike have something they want to accomplish that can only be done using WordPress functions and PHP. This seminar introduces two methods of customizing Thesis 2.1 using PHP.

In the first half of the seminar we will look at the traditional WordPress way using the files Thesis provides for doing this. In the second half we will look at the Thesis 2.1 Box API and perform the same task by creating a custom box.

The practical example we will be following emerged from a Live Q&A session last week. We will be looking at how to modify the length of an excerpt and adding a “Read More” link to the excerpt.

Paid Members can download the practice files from the link below – You must be logged in to see the link

[private 6 month|Annual|Monthly|Founding|Founding – lifetime|Founding – monthly]


Introduction – Using Custom PHP

  • What are we going to do?
  • Who is this Seminar for?
  • What tools do you need to follow along?
  • How might you use it in other applications?

Using the Thesis Custom PHP files

  • Understanding the Thesis file structure
  • The files – custom.php and master.php
  • The difference between the two
  • Anatomy of the custom files

Introduction to WordPress Action Hooks and Filter Hooks

  • What is an action hook?
    • A WordPress function
    • An action hook is a place where you can attach your own functions
    • Can also be used to remove existing hooked options
  • Where are the action hooks?
    • 2 Different hook locations
    • During the processing of the webpage
    • Within the output of the webpage
  • Common WordPress action hooks within processing of a webpage
    • init
    • plugins_loaded
    • theme_setup
    • pre_get_posts
    • template_redirect
  • Common WordPress action hooks within the output of a page
    • wp_head
    • wp_footer
  • What is a filter hook?
    • A WordPress function
    • It contains some value that you can manipulate
  • Where are the filter hooks?
    • This distinction doesn’t matter with filter hooks
  • Common WordPress filter hooks
    • the_content
    • the_excerpt
    • login_headertitle
    • except_length
    • excerpt_more

Write our first function Using a WordPress Action Hook

  • Anatomy of a function
    • function name
    • parameters
    • function directives
    • hook
  • function name – use preface
  • hook
    • hook name
    • function name
    • priority
  • Hello world

Write our first function Using a WordPress Filter Hook

  • Anatomy of a function
    • function name
    • parameter
    • function directives
    • return statement
  • hook
  • Hello world

Example #1 – Change the Number of Words in an Excerpt

  • WordPress filter excerpt_length
  • Using conditional template tags

Example #2 – Add a Read More Link to the Excerpt

  • WordPress filter excerpt_more
  • Using conditional template tags

Advantages & Disadvantages of Adding Custom Programing Using the Thesis Custom Files

  • Advantages
    • Typical of WordPress programming
    • Similar to most other themes
    • Lots of tutorials out there
  • Disadvantages
    • Cumbersome (even impossible sometimes) to apply it to narrow conditions
    • Cumbersome to create user selectable options

The Thesis 2 Way – Box API

  • The fundamental concept
    • Repeatable, user configurable code
  • Thesis Developer Documentation
    • Box API
  • Anatomy of a Thesis 2 box
    • Folder
    • File Name
    • Header
    • Class
    • Core Properties
      • $type
      • $title
      • $name
    • Core Methods
      • html()
    • Options
      • html_options()
      • options()
      • template_options()

Example #3 – Bare Bones Hello World Box

  • Create a folder
  • Create a file
  • Add header
  • Add Class declaration
  • Add property type
  • Add translate function
    • $title only
  • Add html function
  • Add $name to make a multi instance box

Example #4 – Create a Custom Excerpt Box

  • Copy & Modify the Hello World Box
  • Add the html method
  • Add the excerpt
  • Add the filter
  • Hook the filter

Example #5 – Add Options with the html_options() Method

  • What are HTML Options?
    • Specify id & class
    • HTML tag
    • Make available automatic tabbing
    • Anything else you want to add that is edited within the box
  • Syntax
    • Options are always returned
    • Takes an array of html tags – or not
  • Bare bones
  • Observe the results
  • Add HTML tags
    • syntax = value => label
    • default
    • Unset ID
  • Use the options in the output
    • initialize the variables
      • $tab
      • $class
      • $html
    • Write the opening html tag
    • Write the closing html tag

Example #6 – Add the Option to Set the Excerpt Length

  • Create the new HTML option
  • Thesis Options API
    • type
    • label
    • length
    • placeholder
  • Syntax
    • property => value
  • Access the option
  • Alter the filter

Example #7 – Add the Read More Link to the Excerpt

  • Create the new HTML option
    • length = short
    • placeholder = Read More
  • Create the filter function
  • set the value of a variable
  • return the link
  • Add the filter hook to the html function

Question and Answer

0 Comments… add one
0 comments… add one