Modifying the Footer

The next step in our custom home page layout is to modify the footer so that it includes a list of the blog's top-level pages. We now know that get_footer will look for a file called footer.php and include it. But if you call it with an argument, as in get_footer('homepage'), it will instead pull in footer-homepage.php. Near the bottom of home.php, you'll see where home.php calls on get_footer:

chapter_05/v1/wicked/home.php (excerpt)

// calling footer.php get_footer();

To call on another file instead, give it an argument:

chapter_05/v2/wicked/home.php (excerpt)

// calling footer.php get_footer('homepage');

Of course, this will do very little for us at the moment—we'll need to create footer-homepage.php. Again, copying from the parent theme is a great idea. We'll copy footer.php from Thematic, and place it into our child theme, renaming it footer-homepage.php. It looks like this:


// action hook for placing content above the footer thematic_abovefooter();

// action hook creating the footer thematic_footer();

// action hook for placing content below the footer thematic_belowfooter();

if (apply_filters('thematic_close_wrapper', true)) { echo '</div><!-- #wrapper .hfeed -->';

// calling WordPress's footer action hook wp_footer();

// action hook for placing content before closing the BODY tag thematic_after(); ?>

Around line 13, thematic_footer appears: this controls the display of the footer text, which you can set in the options panel Thematic provides to the WordPress admin section. We'll learn more about custom options panels and how you can create one for your child theme in Chapter 7.

Now, to put the list of pages in: WordPress's wp_list_pages5 function will do exactly that. Most times when you find yourself wanting to include some additional content in your theme, WordPress will have a function ready to provide the information you need. Just have a look around the Codex: most functions have names that give a clear idea of what they do.

We could plop wp_list_pages right there in our new home page footer template, and it'd all work fine. But as a point of good housekeeping, it's a better idea to stash this away in our functions.php file. functions.php tends to serve as a catch-all for the custom functionality you add to your child theme. By storing our page list generator in there, we ensure that if we ever need to call on it in some other part of our template, we can find it easily and refer to it in a simple fashion. Pop open that functions.php file and write your first custom function:


<?php function wicked_footer_pagelinks() { echo '<ul id="simplepages">';

wp_list_pages('depth=1&sort_column=menu_order&title_li='); echo '</ul>';

It's fairly straightforward: we're using PHP's echo function to spit out a ul element wrapping the list of pages, with an id so we can target it easily in our CSS. The only tricky part is the argument string passed to wp_list_pages.

As always, the ultimate reference for understanding how to use a WordPress function is the Codex, but I'll break down the arguments I'm using here. depth specifies how far WordPress should dig into the site's page hierarchy. By specifying 1 , we're telling WordPress that we only want top-level


pages. sort_column specifies how the pages should be sorted. There are a number of different options that can be provided here: you can sort by ID, name, author, date modified, and so on. menu_order is the way the pages are ordered by the user in the admin section, so it's a sensible choice. title_li is used to set a title that will appear at the top of the list. By passing in 11 (an empty string), we're telling WordPress to omit the title, and also not to wrap the pages in a ul (since we're providing that ourselves).

Again, all these parameters (and several others) are described on the Codex page for the wp_list_pages, so you should have a read through that, or the page of any WordPress function you plan on using.

Now that we've created our function in functions.php, back in our footer we can call on the function like so:

chapter_05/v2/wicked/footer-homepage.php (excerpt)

Was this article helpful?

0 0

Post a comment