Build Your Own Business Website header image

Lesson 16 – Thesis Custom Loop API

Difficulty Level -

Filed Under Topics -

Listed Under Lesson Subjects -

Applies to -

This Thesis theme video tutorial lesson of our Customize Thesis Like a Pro course provides an introduction to the Thesis Custom Loop API including what it is, when to use it and how it works. Then we cover the Thesis loop class, the loop process, what makes up the loop and review some examples from the Thesis Theme User Guide.

We follow up the basic instruction with four examples of how to use the Thesis Custom Loop API focusing on various ways to display WordPress and Thesis post content.

Introduction to the Thesis Custom Loop API

  • What is the Custom Loop API?
  • When to use the Custom Loop API
  • How it works

Anatomy of the Custom Loop API

  • The thesis_loop Class

    • Constructor ties query types to methods
    • Defines a method for each type of query
    • Defines a filter for each method
    • Relates each method to a default loop
    • Defines 4 default loops
      • Page loop
      • Home loop
      • Single loop
      • Archive loop
  • The loop process

    • Query type is called
    • If a filter is defined for the method then the filter is used
    • Otherwise the default loop is used
  • 2 Parts of a custom loop

    • The extended class
    • The new instance
  • The extended class can contain

    • Replacements for the defined methods
    • New methods to provide additional functionality
  • Thesis User Guide examples

    • Custom Loop API
      • Extended class is instantiated
      • Extended class is defined
      • Defined methods are replaced
    • Thesis Skin Starter Kit
      • Extended class is defined
      • A constructor method is created
      • New methods are added
      • Defined methods are replaced
      • Extended class is instantiated

Example #1 Display 1 Teaser Per Row on the Home Page

  • Tour the existing home loop

    • Sets up variable counters
    • Checks to see if a teaser should be displayed
    • If not –
      • display the post
      • increment the post count variable
    • If so –
      • setup opening and closing html
      • open the box
      • write the teaser
      • close the box
      • increment the teaser count variable
  • Our Logic

    • Stays the same
    • Except that we open and close the box after every teaser
    • $right will always be false
  • Create the extended class

  • Create the new home method

  • Instantiate the class

  • Create the CSS

Example #2 Display 3 Teasers Per Row for Specific Categories

  • Tour the existing archive loop

    • Gets the Thesis options
    • Gets the archive intro
    • Checks to see if titles should be displayed
    • If not titles then use the home loop
    • Home loop teaser –
      • checks the remainder
      • sets open and close html
      • open the box
      • write the teaser
      • close the box
      • increment the teaser count variable
  • Our Logic

    • Stays the same
    • Except that we don’t check for featured posts
    • Except that we open and close the box after every 3rd teaser
    • $right will sometimes be true
  • Create the new category method

    • Thesis archive intro
    • Open/close logic
      • We need a beginning and ending condition
      • Open on first teaser (or 4th, 7th, 10th, etc)
      • Wrap on second teaser
      • Close on third teaser
    • Add a finished condition
  • Create the CSS

  • Limit to specific categories

    • Add conditional statement
    • Default to thesis_loop::category
  • Remove the sidebars from the specific category

    • Create a constructor
    • Create an init
    • Create a filter
    • Create a filter method
      • Add the filter logic
  • Edit the CSS

Example #3 Display a Grid of Post Thumbnails for Specific Categories

  • Our Logic

    • Eliminate all of the teaser related code
    • Wrap it in a post_box and format_text divs
    • Display only Thesis thumbnail and link to post
    • Close out the divs
    • Don’t limit the number of posts displayed
    • Remove the sidebar
  • Add a new conditional to our method

    • Thesis archive intro
    • Opening wrappers
    • The loop
    • Thesis post image and link
    • Close the wrappers
  • Create the CSS

  • Write the function to change the posts per page setting

    • if is category apples
    • if is main query
    • set the query variable
  • Add the filter

  • Add the no sidebars filter

Example #4 Create a Custom Teaser Configuration

  • Map out the Custom Teaser

    • Top section
      • Headline
      • Date
    • Main Section
    • Left
      • Thumbnail
      • Comment count
      • Link
    • Right
      • Excerpt
  • Our Logic

    • Everything is a teaser
    • Don’t need to count teasers
    • Each teaser is wrapped in teasers_box & teaser
  • Restructure the teaser

    • Look at the Thesis teaser
    • Top Section
      • Get the title
      • Get the post date
    • Create left side
      • Thesis post image
      • Thesis comments
      • Thesis teaser link
    • Create the right side
      • Thesis excerpt
    • Clearing div
  • Write the CSS

    • title
    • teaser left
    • teaser right
    • format teaser margin
    • teaser_comments & teaser_link

Question and Answer

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 Comments… add one
0 comments… add one

Leave a Comment