Build Your Own Business Website header image

Lesson 6 – Using Secondary WordPress Loops

Difficulty Level -

Filed Under Topics - , ,

Listed Under Lesson Subjects -

Applies to -

This is the sixth lesson in our Customize Genesis Like a Pro video tutorial course but it’s also the fourth lesson on how to customize the Genesis Theme using PHP. Here you’ll learn how to use Secondary WordPress Loops. We begin with what a WordPress Loop is and how it works. We show several ways to create a them and what parts they are made up from. Then we take you through 5 examples of ways to use WordPress Loops to customize your site.

What is a WordPress Loop?

  • The process of getting information from the database and displaying it on the page
  • Loops in action
    • The page loop – simple loop, retrieves one piece of information
    • The single post loop – the same
    • Blog page loop – retrieves several posts and loops through them
    • Archive page loop
  • The main loop
    • Retrieves the primary content of the page
    • Can contain secondary loops
  • Secondary loops
    • Any other loop besides the main loop
    • Examples of secondary loops
      • comments
      • widgets
      • byobwebsite examples

Example #1 – Add a List of Posts From a Single Category

  • Create the function
  • Define the Query Parameters
    • category
  • Write the query
  • Configure the output
    • Post title
  • Clean up
  • Define the hook
  • Test
  • Add Genesis HTML

Anatomy of a Secondary WordPress Loop

  • Several ways to create a secondary loop
    • query posts – this is the main query object
    • WP Query – the preferred method
      • Creates a new query
      • Separate from the main query
  • 4 parts of a Secondary Loop
    • Define the query parameters
      • 2 methods of annotation
        • query string
        • associative array
      • variable
      • associative array
    • The query
    • Display the results
    • Clean up
  • WordPress Query Parameters
    • Taxonomy Parameters
      • Category parameters
      • Tag parameters
      • Custom taxonomy
    • Page type parameters
      • Post
      • Page
      • Post type
      • Archives
    • Post meta parameters
    • Pagination parameters

Example #2 – Add LINKS to the List of Posts From a Single Category

  • Category query parameters
  • get_the_title()
  • the_permalink()
  • Add a heading
  • Add multiple loops with different criteria

Example #3 – Create a grid of Post Thumbnails in Genesis

  • get_the_post_thumbnail() function
  • Link the image to the post
    • get_permalink();
    • get_the_title();
  • The hook
  • Set priority
  • Set pagination
  • Borrow Genesis HTML

Example #4 – Display a Grid of Custom Posts on the Front Page

  • Custom post type query
  • Display the ‘output’ element of the array
  • Link the image to the post
    • get_permalink();
    • get_the_title();

Example #5 – Create a Grid of Portfolio Images

  • thesis_post_image_info function
  • Display the ‘output’ element of the array
  • Link the image to the post
    • get_permalink();
    • get_the_title();

Question and Answer

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 Comments… add one
0 comments… add one