Select Page
Web Design II
Class 08: Theme Header & Footer

Topics

  • Partial Templates
  • Hooks
  • Week 08 Custom Theme Site (header & footer) Lab

Class 08, future is unclear

Partial Templates

Partial Template:

Templates are the shell of the page the user inputs their content into. A partial template is a template for just part of a page. The most common partial templates are header.php, footer.php, content.php, and sidebar.php. These combine together to make a whole page.

This is handy because it allows you to modulate the different aspects of a page. Usually the header and footer are the same from page to page for example and this allows you to attach a template as oppose to having to recreate them for each page template type.

Hooks

Hooks:

Hooks allow a piece of code to interact and modify another piece of code at a specific location/time. They come in to flavors, Actions and Filters.

Actions:

Action hooks allow you to add operations or modify operations of WordPress during specified execution points. We use these to load in files and features.

“an action takes the info it receives, does something with it, and returns nothing. In other words: it acts on something and then exits, returning nothing back to the calling hook.” -wordpress.org

Filters:

Filter hooks change data during WordPress operations. We haven’t used these. They are excellent for modifying content such as applying a class to an element so that you may target it with CSS.

“a filter takes the info it receives, modifies it somehow, and returns it. In other words: it filters something and passes it back to the hook for further use.” -wordpress.org

Action Hook Example (used last week)
<?php

function my_files() {
    wp_enqueue_style('main_styles', get_stylesheet_uri());
}

add_action('wp_enqueue_scripts', 'my_files');

?>
Filter Hook Example
<?php

function custom_css_body_class( $classes ) {
    if ( ! is_admin() ) {
        $classes[] = 'theme-class';
    }
    return $classes;
}
add_filter( 'body_class', 'custom_css_body_class' );

?>

This example will add theme-class to the body HTML tag.

Hook Triggers:

Most hooks are triggered automatically by certain events that they are attached too. Some however, you will want to declare such as:

  • wp_head();
  • wp_footer();

This allows actions and filters attached to these events to operate correctly.

Hook Triggers Examples
<?php 

wp_head();

if ( have_posts() ) : 
    while ( have_posts() ) : the_post();
        the_title(); 
        the_content();
    endwhile; 
endif; 

wp_footer(); 

?>

Class 08 Custom Theme Site (header & footer) Lab

Custom Theme Site (header & footer) Lab

A header and footer section will be added to the theme “sandwich”.

You will be graded on the following:
  • Lab Requirements
    • Techniques and processes covered in the instructional material is followed and implemented.
  • Creativity & Craftsmanship
    • Excellent design choices, novel & appealing, and solid clean caliber work.
Resources:
Assignment Video Tutorials
You may watch these tutorial videos below to help you complete your assignment.

Lab Tutorial Slideshow

This tutorial will review WordPress as well as setup a site to apply our future custom theme to.

Lab Introduction
Custom Theme Site (header & footer) Lab
PlayPlay
Introduction

Your functioning theme displays your pages but not a header or footer. This means there is no menu to navigate from one area to another. In this lab we will create the header and footer partial template files as well as link other files and update what has been created thus far. This will be the longest most complex lab in this course. Hang in there, you can do it.
Click on the > to start

You may use what you created in the last lab .

 

Wait! Before you go!

Did you remember to?

  • Read through this webpage
  • Watch the videos
  • Submit Class 08 Custom Theme Site (header & footer) Lab on Blackboard